PHP PDF Templates and PHP PDF Importing

You can use the TCPDF and FPDI libraries to import PDF pages from one PDF into another PDF.

FPDF-TPL

FPDF-TPL extends TCPDF to provide PDF forms / templates

FPDI

FPDI extends FPDF-TPL to provide PDF page importing

Examples

split multipage PDF into multiple PDFs
require_once 'tcp/tcpdf.php';
require_once 'fpd/fpdi2tcpdf_bridge.php';
require_once 'fpd/fpdi.php';

for ($i=1 ; $i <= 10 ; $i++)
{
    $pdf = new FPDI('L','pt','A2');
    $pdf->addPage();
    $pc = $pdf->setSourceFile("in.pdf");
    $pg = $pdf->importPage($i);
    $wh = $pdf->useTemplate($pg);
    var_dump($wh);
    $pdf->Output("$i.pdf",'F');
    unset($pdf);
}


write all pages of one PDF on top of each other with offset into a single PDF
require_once 'tcpdf/tcpdf.php';
require_once 'fpdf/fpdi2tcpdf_bridge.php';
require_once 'fpdf/fpdi.php';

$pdf = new FPDI();

$pdf->addPage();

$pc = $pdf->setSourceFile("in.pdf");

for ($i=1 ; $i <= 6 ; $i++)
{
        $pg = $pdf->importPage($i,'/MediaBox');
        $pdf->useTemplate($pg,0,0);
}

$pdf->Output('out.pdf','F');


write first page of five PDFs on top of each other into a single PDF
require_once 'tcpdf/tcpdf.php';
require_once 'fpdf/fpdi2tcpdf_bridge.php';
require_once 'fpdf/fpdi.php';

function inc($pdf,$file) {
        static $x ,$y;

        $pc = $pdf->setSourceFile("$file.pdf");
        $pg = $pdf->importPage(1,'/MediaBox');
        $pdf->useTemplate($pg,$x,$y);

        $x+=30;
        $y+=30;
}

$pdf = new FPDI();

$pdf->addPage();

for ($i=1 ; $i <= 6 ; $i++) {
        inc($pdf,$i);
}

$pdf->Output('pdf.pdf','I');




REFERRERS
PhpPdf
TCPDF

There are no comments on this page. [Add comment]

Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki