Jul 24

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.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • LinkedIn
  • Live
  • NuJIJ
  • Print
  • Slashdot
  • TwitThis
  • Yahoo! Buzz
  • eKudos
  • Hyves
  • MySpace
  • StumbleUpon
  • Technorati
  • MSN Reporter
  • Symbaloo
  • Twitter
  • Reddit

25 Responses to “FPDF error: Unable to find xref table”

  1. Lukas says:

    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 says:

    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 says:

    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 says:

    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 says:

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

  6. Deepa says:

    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.

  7. Patrick says:

    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

  8. Deepa says:

    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

  9. Patrick says:

    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?

  10. Deepa says:

    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

  11. Patrick says:

    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.

  12. Deepa says:

    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.

  13. Patrick says:

    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!

  14. Deepa says:

    Thanks Patrick..

  15. Deepa says:

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

    Thanks,
    Deepa

  16. Ramin says:

    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

  17. Patrick says:

    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

  18. Deepa says:

    Thanks Patrick !!

  19. Dan says:

    @patrick

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

  20. Patrick says:

    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.

  21. Jules says:

    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’

  22. Patrick says:

    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.

  23. Ian says:

    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!

  24. Ian says:

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

    Thanks!

  25. Derrick says:

    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.

Leave a Reply

preload preload preload