Hi,
I am using CI and FPDF with FPDFI, http://www.fpdfi.org
I have it set up and working pretty well, and have been using theses to generate a lot of PDF’s in the last couple of years, but now I have a different issue,
I am trying to generate a bunch of separate PDF’s inside a for loop.
The Basic’s of my controller are;
<?php
// inside my CI controller
function monthly() {
// Load PDF Library - now loading in loop to try reset buffer
// $this->load->library('pdf');
// Load and initialise CI Email library
$this->load->library('email');
$this->email->initialize(array('mailtype' => 'html'));
// start loop - approx 15 records
$monthlies = $this->invoice->getMonthlies();
if($monthlies) {
foreach($monthlies as $monthly) {
// Load CI/FPDF library
$this->load->library('pdf');
// Create PDF ( I have remove unnesscary code that pulls data for PDF. )
// Make a random filename
$filename = md5(time() * rand(100, 1000)) .'.pdf';
$this->load->view('pdf/invoice', array('filename' => $filename));
// validate customer email and sent PDF.
if(valid_email($email)) {
$this->email->from($this->config->item('admin_mail'));
$this->email->to($email);
$this->email->reply_to($this->config->item('admin_mail'));
$this->email->subject('Invoice #'. $invoice_id);
$this->email->message($this->load->view('admin/email', array('customer' => $customer, 'invoice' => $invoice), TRUE));
// Attach my PDF, send and clear email + all attachemnts
$this->email->attach($filename);
$this->email->send();
$this->email->clear(TRUE);
}
// end loop
}
}
// finished
redirect();
}
}This script run’s and emails each record as expected, but it is concatinating my PDF’s in to one PDF, EG; 1st loop, correct single page PDF, 2nd loop, 1st page is the previous record, second is a blank PDF page ?
15th record, as the first PDF correct, and a random amount of blank pages.
My PDF View generates a single PDF fine, I have tried to reset thte PDF buffer after my output;
$this->pdf->Output($filename, 'F');
$this->pdf->closeParsers();
$this->pdf->Close();
unset($this->pdf->buffer);
$this->pdf->buffer = '';
$this->pdf->buffer = NULL;My CI PDF library includes the fpdfi library like so;
<?php
if(!defined('BASEPATH')) exit('No direct script access allowed');
require_once('fpdi.php');
class Pdf extends fpdi {
var $fontsize = 8;
function Pdf() {
parent::fpdi('P','mm','A4');
$this->AddFont('HelveticaNeue-Light','','HelveticaNeue-Light.php');
$this->AddFont('HelveticaNeue-Light','B','HelveticaNeue-Bold.php');
}
function Header() {
$ci =& get_instance();
$this->SetY(40);
}
function Footer() {
}
}