Reputation: 245
Is there any function that I could call in order to include an existing pdf in my fpdf
file?
For example
$pdf->AddPage(from file example.pdf);
something like that? is it posible?
Upvotes: 5
Views: 29678
Reputation: 11914
The Answer to this Question is that FPDF needs boosting by means of an additional library.
One such "Free" PHP library is MIT licensed "Setasign" FPDI which enhances FPDF
but can also be used with TCPDF and tFPDF. You need to install the PDF generation library of your choice along with FPDI.
FPDI is a collection of PHP classes facilitating developers to read pages from existing PDF documents and use them as templates in FPDF.
More details and a download location are available via https://www.setasign.com/products/fpdi/downloads
The development repository and "Issues" support of FPDI is available on GitHub at https://github.com/Setasign/FPDI
FPDI can also be installed via Composer. The related package is available on Packagist.
A code example related to the question:
<?php
require_once('fpdf/fpdf.php');
require_once('fpdi2/src/autoload.php');
$pdf = new \setasign\Fpdi\Fpdi();
$pageCount = $pdf->setSourceFile('Fantastic-Speaker.pdf');
$pageId = $pdf->importPage(1, \setasign\Fpdi\PdfReader\PageBoundaries::MEDIA_BOX);
$pdf->addPage();
$pdf->useImportedPage($pageId, 10, 10, 90);
$pdf->Output('I', 'generated.pdf');
If you wish to embed multiple PDFs into a "Portfolio" you would need to use SetaPDF-Merger Which is NOT "Free" see https://manuals.setasign.com/setapdf-merger-manual/portfolios/
Upvotes: 0