FPDF error: Unable to find xref table

Today I faced a problem with FPDF and FPDI when trying to concatenate some PDF files. The only output I got was ‘FPDF error: Unable to find xref table.’ When I did a search on this error message, I wasn’t able to extract the answer from it. After some searching, the problem was located.

One of the PDFs which should be merged was originally created from Word by a PDF creator which placed its signature in the properties of the PDF document. After removing this signature (in this case opening the PDF with Adobe Illustrator and saving it again) the problem was solved.

Compression and stream

The FPDF / FPDI classes use the input stream of the PDF file to create the concatenated PDF. Setasign remarks that the stream is only used (and altered) in the free version. The paid version should not give such errors. As I’ve experimented with the free version, I’ll treat that one here.

Because of compression, some applications might leave out or mess up the xref property. Although this results in a PDF file which can be opened in a PDF reader, the stream is not according to the ‘standards’. In such a case the document markup is ‘lost’ and applications / scripts using this property cannot handle these files any more.

PDF merging code example

To show how PDF files can be merged by using FPDF and FPDI I’ve compiled a little example which can be downloaded here. The archive consists of FPDF version 1.6, FPDI version 1.3.1, FPDI_TPL and two sample PDF files which were created with Microsoft Word 2007. The executing script is concat.php. Run this script to concatenate the two sample PDF files together in a new PDF file.

Possible solutions

A paid version of FPDI might be an option, but let’s have a look at other possible solutions.

Opening the file and saving it again with a better pdf creator might fix the problem as it reformats the stream which is saved.

Final remarks

When you’re creating the source PDF files yourself, watch out which pdf creator you use. Although the visual result might be the same, the stream might not be.

Getagged , ,

43 reacties op “FPDF error: Unable to find xref table

  1. Lukas schreef:

    Hi Patrick

    I am facing the same problem with a PDF generated using Distiller 9.0 trough Word.
    I tried your workaround with the Illustrator CS4 but it didnt work. Maybe you were using a different version?
    I’d really appreciate any help with this problem.

    Lukas

  2. Patrick schreef:

    Hi Lukas,

    A search on ‘Distiller 9.0 xref’ took me to this page. It could be that the PDF generated by Distiller is incompatible as that source suggests.
    I had my problem using PrimoPDF if I remember correctly. You could also try to use that to generate a PDF from a Word file of course.
    If it doesn’t work, please reply so we can look into it further.

    Cheers!

    Patrick

  3. Lukas schreef:

    Hi Patrick

    I got my problem solved:

    When trying to print using the usual PDF printer by Adobe you have to change the option converter from Distiller to Acrobat.

    I guess PDFI doesnt like the Distillers compression…

    Well, anyway… thank you for your help.

    Lukas

  4. Patrick schreef:

    No problem. Thanks for replying!
    I’ll add your findings to my blogpost so it might be of help for more people.

    Patrick

  5. Deepa schreef:

    Hello,
    I am getting same error. I tried this alternative but it doest work.
    Do you have any other solution?

  6. Deepa schreef:

    This is my sample code.
    setSourceFile(‘TestDoc1.pdf’);
    $tplidx=$pdf->importPage(1,’/MediaBox’);
    $pdf->addPage();
    $pdf->useTemplate($tplidx,10,10,90);
    $pdf->Output(‘newpdf.pdf’,’D’);
    ?>
    When I am running this, I am getting error:
    FPDF error: Unable to find xref table.
    —-
    I tried to Save As PDF document in Adobe Acrobat 9 Pro. But that doesnt work.

    • Patrick schreef:

      Hi Deepa, did you save the TestDoc1.pdf with Adobe Acrobat Pro 9? If so: by which creator was the PDF originally created? As with earlier reported problems, it might have to do with that generator’s compression.. Please let me know so we can investigate it.

      Cheers!

      Patrick

  7. Deepa schreef:

    HI Patrick,
    Thanks for yr response.
    I have downloaded PDF by running this sample code,
    http://www.setasign.de/products/pdf-php-solutions/fpdi/demos/simple-demo/

    And I have save TestDoc1.pdf to the htdocs folder of the Apache server as I am running in Localhost.

    Here is the whole code,
    setSourceFile(‘TestDoc1.pdf’);
    $tplidx=$pdf->importPage(1,’/MediaBox’);
    $pdf->addPage();
    $pdf->useTemplate($tplidx,10,10,90);
    $pdf->Output(‘newpdf.pdf’,’D’);
    ?>

    -Deepa

  8. Patrick schreef:

    I’ve ran the same fpdi code from setasign as you did for my blogpost. You have set your TestDoc1.pdf as your source file. That’s okay.

    My previous question was actually HOW you created TestDoc1.pdf. The error you’re receiving has to do with the input (source) file. The code itself is okay.
    Did you create TestDoc1.pdf yourself? If so, with which application? Or did you download it?

  9. Deepa schreef:

    Hi Patrick,

    I have created TestDoc1.pdf by downloading it form the seasign website. So it is downloaded file. I haven’t created it.

    Thanks,
    Deepa

  10. Patrick schreef:

    I’ll have a look at it. It might have to do with the compression used by the program which they used to create the PDF. I’ll let you know a.s.a.p.

  11. Deepa schreef:

    Thanks.

    I have installed PrimoPDF as you have mentioned in your other posts. I have created some PDFs through that too and tried. I have right clicked one word document and CONVERT TO ADOBE PDF. And used that PDF in setSourceFile(). But that doesn’t work too.

  12. Patrick schreef:

    Hey Deepa, I will try to generate a PDF file tomorrow and see if it works with the code I have. If it does I will post it here!

  13. Deepa schreef:

    Thanks Patrick..

  14. Deepa schreef:

    Hi Patrick,
    Did you get any solution for this? Please let me know as soon as you done.

    Thanks,
    Deepa

  15. Ramin schreef:

    Hi
    I have the same problem but i cant change the pdf file have you any idea to solve this TCPDF return same error message.
    TCPDF ERROR: Unable to find xref table.
    please connect via email to discuss more about it.
    tanx a lot

  16. Patrick schreef:

    Deepa,

    I’ve got it working. I’ve created two PDF files with Word 2007 and I can concatenate these. I’ll post some details today, and I will make my code available as a download.

    Sorry it took me a little longer than I wished!

    Cheers

  17. Deepa schreef:

    Thanks Patrick !!

  18. Dan schreef:

    @patrick

    Any status on what you did to get word 2007 working?

  19. Patrick schreef:

    Dan,

    How do you mean ‘to get Word 2007 working’?
    To get Office 2007 working is pretty simple: buy it and install it.
    Word 2007 has a PDF export function which I used (nothing more, nothing less). This produces a PDF which can be used to concatenate to another file.

  20. Jules schreef:

    Im getting this error on my server wat can I do:

    this is the error:

    mPDF error: Unable to find xref table – Maybe a Problem with ‘auto_detect_line_endings’

    • Patrick schreef:

      Hi Jules,

      It’s hard to find information on this. I’ve came across some posts in which people notice that the EOL characters are changed. This could be the reason.
      In this thread it is suggested that it has something to do with unsupported fonts.
      I see that you’re using mPDF. I’ve used FPDF and FPDI for my example. Perhaps you could give that a try to see if you encounter the same error.

  21. Ian schreef:

    Hi Patrick,

    I have created a PDF using Adobe Pro 9 from Word 2003. When I have uploaded this to our website and then tried to download it (as our users would) I get the error: FPDF error: Unable to find xref table – Maybe a Problem with ‘auto_detect_line_endings’ .
    I have heard it may be the ‘signatures’ in the word document but I cannot find any in the document (looking under ‘security’ and digital signatures). I am a bit of a loss here, being very new to Adobe and also pretty much clueless on server/website stuff.
    Any help would be much appreciated!

  22. Ian schreef:

    Ok…feel a fool now, just read again through your previous posts and solved my problem (was the compression settings).

    Thanks!

  23. Derrick schreef:

    PDF for some reason has changed up how the handle the xref table after version 1.4, and Setasign is charing to be able to read these newer compress version of the file, the paid version does work.

    For my company it was not fessable to have everyone convert their files to 1.4 or lower but if this is an option for you you can open the pdf document, click print and change your printer to Adobe PDF, the click on properties. Under the Adobe PDF settings tab change the Default Settings to PDFA1b 2005 CMYK and this should solve your problelm.

    I am not 100% sure what these differerent setting do but this worked as a initial fix.

  24. MARKIS schreef:

    I KNOW THE ANSWER 🙂

    Use Adobe Acrobat Pro and covert or save your source file to pdf/a
    INFO: http://en.wikipedia.org/wiki/PDF/A

  25. Jaco schreef:

    Hi guys,

    I’ve had this error on certian files and opening with adobe pro and saving worked for some but not all. So I looked at the code and FPDI uses the first 100 bytes of the PDF file to look for the xref table. I changed this to be the first 200 bytes and it worked for all my files. I guess it could be that as Adobe Distillers change they put the demarcation of the start of the xref in different places. Using the entire file size would probably be best but will also slow the process down. There should actually be a better way of looking for the xref table.

  26. Aaron schreef:

    I was able to fix this by using Adobe Acrobat Professional v8 and going to “Document -> Reduce File Size” and then choosing something really old like “Acrobat 5.0 or Later”, then the error was fixed!

  27. renevdkooi schreef:

    I had the same problem, any version I used didn’t work. Saving with PS CS5, AI CS5, then tried CS4 etc. nothing

    What I did was:
    made the file ready as a pdf, moved the file to a windows machine with cutepdf virtual printer installed and pretended I was printing the file. That created a compatible multi page pdf file, which it could read.

    Hope it can help someone else, coz it took me 2 hours or so… 🙁

  28. Felix schreef:

    Jaco, where in the code does FPDI look for the xref table? Thanks.

  29. Felix schreef:

    Never mind, I found it.

  30. apy schreef:

    Hi, I write from Italy sorry for my bad English.
    I have an application written in PHP using FPDF libraries FPDI + to concatenate PDF files but for some files I get the error ‘FPDF error: Unable to find xref table’, I saw in the files of the two libraries and found the function called function error ($ msg) that contains the following statement “die (‘ FPDF error: ‘. $ msg);” that causes the error message: how can I change this statement so that my application in case of ‘FPDF error: Unable to find xref table’ go ahead without crashing? I am new to php … Thanks to all

  31. Mitch schreef:

    After spending hours trying various settings/applications, the CuteWriter solution (as posted by renevdkooi) worked for me.

  32. supreet schreef:

    Hi, i am trying to upload files to my server, through fpdi, and i am encountering the error FPDF error: Unable to find xref table.
    I tried few of the solutions above, but none worked. Please help

  33. Chris schreef:

    I am using fpdi with a drupal install. In order to get the file url, I used the Drupal API function file_create_url(). It was driving me crazy for hours messing with the PDF file to try and figure out why it was happening. All along, the issue was that I was passing an absolute url rather than a relative one. So http://domain.com/yourfile.pdf will not work, yourfile.pdf will.

  34. ANIL schreef:

    Hi Patrick,

    I have created a PDF using TCPDF function and getting the error.
    How can I fix the code written in TCPDF generated output
    Any help would be much appreciated!

  35. Sage schreef:

    If you’re on a mac, you can open the PDF in Preview.app and File > Save a Version to save it as another PDF. It’ll remove the password protection.

  36. Vincent DECAUX schreef:

    Hello, you can take a look to TCPDI parser. It’s a free version of FPDI parser, and can handle with more PDF versions. https://github.com/pauln/tcpdi

  37. B_Brodie schreef:

    Thanks for this post.

    Had this issue, on a Mac used Preview app to print the original to a new PDF file (in print dialog) and problem was solved.

    I think yes, CutePDF on windows, would also work…

  38. Richard schreef:

    Hey, thanks for this.
    I had an issue where PDF’s generated by MYOB directly would give this error. Printing them to PDFCreator rather than exporting them from MYOB solved the issue.

  39. www schreef:

    can anybody help to fix error Unable to find xref table?
    i googled, download last ver of fpdi but no progress

Geef een reactie

Het e-mailadres wordt niet gepubliceerd. Vereiste velden zijn gemarkeerd met *