I am using codeigniter 3 and working on pdf creation. I am using tcpdf library and now need to use Fpdi library to merge pdfs with Tcpdf but it's not working. In application\library folder i have tcpdf and fpdi library folders. In application\tcpdf folder i have Pdf.php file and in this file i am trying to include fpdi library so that i can use both in controller function. This is code in Pdf.php file.
<?php
if(!defined('BASEPATH')) exit('No direct script access allowed');
//use setasign\Fpdi;
require_once dirname(__FILE__) . '/tcpdf/tcpdf.php';
require_once dirname(__FILE__) . '/fpdi/src/Fpdi.php';
require_once dirname(__FILE__) . '/fpdi/src/FpdfTpl.php';
class Pdf extends TCPDF {
public $my_header_title = "Report";
function __construct() {
parent::__construct();
}
//Page header
public function Header() {
// Set font
$this->SetFont('helvetica', 'B', 20);
// Title
$this->Cell(0, 15, $this->my_header_title, 0, false, 'C', 0, '', 0, false, 'M', 'M');
}
// Page footer
public function Footer() {
// Position at 15 mm from bottom
$this->SetY(-15);
// Set font
$this->SetFont('helvetica', 'I', 8);
// Page number
//$this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
}
}
and i am trying to use it in my Orders Controller. This is code.
$this->load->library('Pdf');
public function multiplePdfGeneration()
{
$pdfNameArr = $_POST['imagesvalues'];
$List = implode(',', $pdfNameArr);
$id = $_POST['sendid'];
$expPdf = explode(',',$List);
$path = $file = FCPATH."createpdf/";
foreach($expPdf as $pdfVal)
{
foreach(glob("$path/{$pdfVal}*") as $imgfilename)
{
$ext = substr(strrchr($imgfilename, '.'), 1);
if($ext=='pdf')
{
$imgName[] = basename($imgfilename);
}
}
}
$count = count($imgName);
$filelocation = FCPATH."/createpdf/multigenerate";
$time = date("d-m-Y")."-".time();
$mainfilename="ID".$id."-multipdf-".$time;
$filename=$mainfilename.".pdf";
$fileNL = $filelocation."/".$filename;
$pdf = new Pdf(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('OrderCal');
$pdf->SetSubject('Invoice Pdf');
$pdf->SetKeywords('Invoice Pdf');
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetMargins(2, 10, 2,true);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$pdf->SetAutoPageBreak(TRUE, 10);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf->SetFont('times', 'BI', 10);
$pdf->my_header_title = '';
for($i=0; $i<=$count;$i++)
{
if($imgName[$i]=="")
continue;
$img11=base_url()."createpdf/".$imgName[$i];
$pdf->setSourceFile($img11);
$tplIdx = $pdf->importPage($i);
$pdf->useTemplate($tplIdx);
}
$pdf->Output($fileNL, 'F');