The customer was given the task - to finish the PDF-document, which is created using the
TCPDF class, you need to attach the scans, too, in PDF-format.
The search for a solution constantly led to the need to use some kind of utility (for example,
Pdftk ), which had to be installed with all the consequences. And since Since hosting was normal, installing additional software is quite problematic. In general, there was a need for a solution that ideally simply extends the functionality of TCPDF (FPDF), or, in any case, is fully implemented in PHP.
In the end, the solution was found -
FPDI . This is an extension of the good old
FPDF , but TCPDF is also supported, which I was especially pleased with.
For ease of use in
CakePHP , I created a component that inherits FPDI.
')
<?php
define ( 'FPDF_FONTPATH' , ROOT . '/vendors/fpdf/font/' );
App :: import ( 'Vendor' , 'fpdf' . DS . 'fpdf' );
App :: import ( 'Vendor' , 'fpdi' . DS . 'fpdi' );
class FpdiComponent extends FPDI {
public function addFile ( $file ) {
$pages = $this -> setSourceFile ( $file );
for ( $i = 1 ; $i <= $pages ; $i ++) {
$this -> AddPage ( 'P' , 'A4' );
$tpl_id = $this -> importPage ( $i );
$this -> useTemplate ( $tpl_id , 0 , 0 , 210 , 297 );
}
}
}
It’s true that you still had to stick PDFs together with FPDF, since for some reason, with TCPDF, blank pages were added for import.