FPDI Fatal error: Uncaught exception 'Exception' with message 'Unable to find object (1, 0)

4.9k views Asked by At

I'm trying to import a pdf with php class FPDI with this simple code:

require_once("fpdf/fpdf.php");
require_once("fpdi/fpdi.php");
$pdf = new FPDI();
$pdf->setSourceFile('intermedia.pdf');
$tplidx = $pdf->ImportPage(1);
$pdf->AddPage();
$pdf->useTemplate($tplidx,0,0,210);
$pdf->Output();

but I receive the following error:

Warning: explode() [function.explode]: Empty delimiter. in /var/catalogo/test_pdf/fpdi/pdf_parser.php on line 369

Fatal error: Uncaught exception 'Exception' with message 'Unable to find object (1, 0) at expected location.' in /var/catalogo/test_pdf/fpdi/pdf_parser.php:709 Stack trace: #0 /var/catalogo/test_pdf/fpdi/pdf_parser.php(268): pdf_parser->resolveObject(Array) #1 /var/catalogo/test_pdf/fpdi/pdf_parser.php(208): pdf_parser->_readRoot() #2 /var/catalogo/test_pdf/fpdi/fpdi_pdf_parser.php(71): pdf_parser->__construct('/var/catalogo/t...') #3 /var/catalogo/test_pdf/fpdi/fpdi.php(128): fpdi_pdf_parser->__construct('/var/catalogo/t...') #4 /var/catalogo/test_pdf/fpdi/fpdi.php(108): FPDI->_getPdfParser('/var/catalogo/t...') #5 /var/catalogo/test_pdf/index.php(5): FPDI->setSourceFile('intermedia.pdf') #6 {main} thrown in /var/catalogo/test_pdf/fpdi/pdf_parser.php on line 709

This is the file that should be imported: http://catalogo.selectaspa.it/test_pdf/intermedia.pdf

1

There are 1 answers

0
Jan Slabon On

Ok, the cross reference of this file is simply corrupted. I just catched the "Warning" on explode for now but at the end you will have to resave the document with e.g. Acrobat to repair it before passing it to FPDI.

You may change pdf_parser.php around line 362 to:

// get Line-Ending
$found = preg_match_all("/(\r\n|\n|\r)/", substr($data, 0, 100), $m); // check the first 100 bytes for line breaks
if ($found === 0) {
    throw new Exception('Xref table seems to be corrupted.');
}

Same fix can be used in the separate FPDI PDF-Parser which will allow you to read this document then, too.