### Import and place a PDF page Source: https://github.com/setasign/fpdi/blob/master/README.md A simple example that imports page 1 from a PDF and places it on a new page. Use the commented alternative classes for TCPDF or tFPDF. Requires the autoload file and a source PDF named 'Fantastic-Speaker.pdf'. ```php AddPage(); // set the source file $pdf->setSourceFile("Fantastic-Speaker.pdf"); // import page 1 $tplId = $pdf->importPage(1); // use the imported page and place it at point 10,10 with a width of 100 mm $pdf->useTemplate($tplId, 10, 10, 100); $pdf->Output(); ``` -------------------------------- ### PSR-4 autoloader registration Source: https://github.com/setasign/fpdi/blob/master/README.md Register the src path with a PSR-4 autoloader to load FPDI classes. Replace the example namespace and path with your own. ```php $loader = new \Example\Psr4AutoloaderClass; $loader->register(); $loader->addNamespace('setasign\Fpdi', 'path/to/src/'); ``` -------------------------------- ### Manual autoload include Source: https://github.com/setasign/fpdi/blob/master/README.md Require the autoload.php file from the src folder when not using Composer. ```php require_once('src/autoload.php'); ``` -------------------------------- ### Composer configuration for FPDF Source: https://github.com/setasign/fpdi/blob/master/README.md Add these dependencies to your composer.json to use FPDI with FPDF. Requires setasign/fpdf 1.9.* and setasign/fpdi ^2.6. ```json { "require": { "setasign/fpdf": "1.9.*", "setasign/fpdi": "^2.6" } } ``` -------------------------------- ### Composer configuration for tFPDF Source: https://github.com/setasign/fpdi/blob/master/README.md Update your composer.json to these dependencies to use FPDI with tFPDF. Requires setasign/tfpdf 1.33.* and setasign/fpdi ^2.6. ```json { "require": { "setasign/tfpdf": "1.33.*", "setasign/fpdi": "^2.6" } } ``` -------------------------------- ### Composer configuration for TCPDF Source: https://github.com/setasign/fpdi/blob/master/README.md Update your composer.json to these dependencies to use FPDI with TCPDF. Requires tecnickcom/tcpdf 6.11.* and setasign/fpdi ^2.6. ```json { "require": { "tecnickcom/tcpdf": "6.11.*", "setasign/fpdi": "^2.6" } } ``` -------------------------------- ### PHP code causing FPDI 'Array value expected' error Source: https://github.com/setasign/fpdi/blob/master/tests/_files/pdfs/PDF-complex-structure.pdf This PHP script uses FPDI to generate a preview of a PDF file. It opens the file, imports up to 5 pages, and outputs the PDF. The error occurs when processing a PDF with a nested object structure. ```php setSourceFile($pdf_handle); $max = min(5, $pageCount); for ($i=1; $i <= $max; $i++) { // Add page to the document $templateID = $pdf->importPage($i); //$pdf->getTemplateSize($templateID); $pdf->addPage(); $pdf->useTemplate($templateID); } $pdf_content = $pdf->Output('S'); header("Content-type:application/pdf"); echo $pdf_content; fclose($pdf_handle); return; } } require("libs/Pdf.php"); $pdf = new Pdf(); $pdf->generatePreview("files/PDF-complex-structure.pdf"); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.