Bonding PDF documents using PHP
A task was set by the customer - at the end of the PDF document that is created using the TCPDF class , you need to attach the scans in PDF format too.
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 hosting was normal, then installing additional software is quite problematic. In general, a solution was needed that ideally simply extends the functionality of TCPDF (FPDF), well, or, in any case, is fully implemented in PHP.
In the end, a 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 inCakePHP , I created a component that inherits FPDI. True, I still had to glue PDFs in conjunction with FPDF, because For some reason, with TCPDF, when importing, blank pages were added.
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 hosting was normal, then installing additional software is quite problematic. In general, a solution was needed that ideally simply extends the functionality of TCPDF (FPDF), well, or, in any case, is fully implemented in PHP.
In the end, a 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 inCakePHP , I created a component that inherits FPDI. True, I still had to glue PDFs in conjunction with FPDF, because For some reason, with TCPDF, when importing, blank pages were added.
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);
}
}
}