1

I need to add pages in an existing PDF document after the first page and as last page. I used to implement it with Zend_Pdf but found out, that it can only handle PDFs of which the cross-reference table isn't compressed to a stream (a feature that was introduced in PDF version 1.5).

So I'm looking for a PHP PDF-Library which can modify existing PDF documents with objects and an xref table stored in a stream as described in ISO-32000-1 (which was based on PDF-1.7).

  • TCPDF cannot modify, only in combination with FPDI (and FPDI can only handle PDF-Version up to 1.4 in the free version)
  • Zend_PDF (as mentioned above) can only handle files to PDF Version up to 1.4. Maybe it would be an idea to try the Zend_Pdf Version from ZF2 from github?
  • FPDF can only handle files to PDF Version 1.4 as I found out

Are there any other PHP PDF libraries for my needs?

Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
Anna Völkl
  • 1,664
  • 2
  • 15
  • 28
  • Have you actually run into any problems with Zend_Pdf? Pages are well-defined separate objects in PDF, so if you open a PDF file with Zend_Pdf and all you do is add a number of additional pages, chances are very high (if Zend_Pdf behaves nicely) that things will simply continue to work. – David van Driessche Feb 06 '13 at 10:16
  • Yes, i had problems with a PDF in Version 1.5. Error: "Cross-reference streams are not supported yet." – Anna Völkl Feb 06 '13 at 10:42
  • 1
    @DavidvanDriessche According to [Zend_Pdf Einführung](http://framework.zend.com/manual/1.12/de/zend.pdf.introduction.html#fnid1) only loading of V1.4 (Acrobat 5) PDF documents is supported. I assume that means cross reference streams are not supported. rescueAnn seems to require support of them. – mkl Feb 06 '13 at 11:05

1 Answers1

0

it seem that FPDI can do a mergin of different pdf document, so you can build you first page an then your other pages and merge it into one with a specified order (Merge PDF files with PHP)

class concat_pdf extends FPDI {
     var $files = array();
     function setFiles($files) {
          $this->files = $files;
     }
     function concat() {
          foreach($this->files AS $file) {
               $pagecount = $this->setSourceFile($file);
               for ($i = 1; $i <= $pagecount; $i++) {
                    $tplidx = $this->ImportPage($i);
                    $s = $this->getTemplatesize($tplidx);
                    $this->AddPage('P', array($s['w'], $s['h']));
                    $this->useTemplate($tplidx);
               }
          }
     }
}

/* uses example :
$pdf =& new concat_pdf();
$pdf->setFiles(array("doc.pdf","pauta.pdf", "4bp.pdf", "5bp.pdf"));
$pdf->concat();
//$pdf->Output("newpdf.pdf", "I");//for printing on screen
$pdf->Output("newpdf.pdf", "F");//for saving it
*/

but for version above 1.4 there is a new conpression used and FPDI support it witha parser bundle but it is not free of charge (100€). you can have a look there Is there a way to make FPDF/FPDI or Zend_Pdf support the parsing of PDFs greater than 1.4? too.

Community
  • 1
  • 1
xavier Z
  • 144
  • 6
  • You're right. But actually I was looking for a free possibility to do the merging. If I won't find one, I'll keep that in mind. Buying PDFlib would be much more expensive anyway. – Anna Völkl Feb 06 '13 at 09:34