Erin Blackwell
Erin Blackwell

Reputation: 1

How can I include the content from an existing pdf into my generated pdf?

I'm using fpdf for the script to create the PDF from my sql data. I want to add a glossary to the end of that content. I looked at fpdi, but you can only add 1 page from the PDF. How can I add all the pages?

Upvotes: 0

Views: 1179

Answers (3)

Adam Jimenez
Adam Jimenez

Reputation: 3145

$pagecount = $pdf->setSourceFile('yourpdf.pdf'); 

// import pages
for ($loop = 1; $loop <= $pagecount; $loop++) {
    $tplIdx = $pdf->importPage($loop);
    $pdf->addPage();
    $pdf->useTemplate($tplIdx);
}

Upvotes: 0

iWantSimpleLife
iWantSimpleLife

Reputation: 1954

How about using a loop to import each page separate.

Should not be to difficult to get the number of pages then loop through the pages.

Upvotes: 0

ghoti
ghoti

Reputation: 46816

From the FPDI documentation... Note the first parameter.


FPDI::importPage()

Description

class FPDI extends FPDF_TPL {

    mixed importPage ( integer $pageno[, string $boxName='/CropBox'] )
}

Transforms a source page to a FPDF_TPL template and returns the id of created "template" (or page in this case).

Parameters

$pageno

  • The page number to import.

$boxName

  • The box which should be used to display the imported page.

    Possible values are:

    • /MediaBox
    • /BleedBox
    • /TrimBox
    • /CropBox
    • /ArtBox

    If a box is not found, FPDI will look up for it's parent box and use this instead. You can check which box were imported with FPDI::getLastUsedPageBox().

Return Values

If the page was imported correctly the method will return the id of the template (page) to use with useTemplate(). If you define a wrong box in the 2nd parameter the method will return false

Upvotes: 1

Related Questions