Search code examples
phppdfmobilefpdf

fpdf - Viewing on mobile not working


I create pdf files in php with fpdf. Everything is working so far but viewing these pdfs on mobile devices is not working.

The acrobat reader on android is closing with the message that the file is damaged. By a customer i know that on iPad opening the pdf file nothing happens... I already tried just to create an empty pdf but same behavior. On Windows with Acrobat Reader and foxit everything is working fine.

I need some ideas how to find the cause.


Solution

  • The file made available by devOp in his comment, link, actually is a damaged PDF as it starts with some garbage before the mandatory %PDF line (cf. the PDF specification ISO 32000-1:2008):

    524.41 102.05 48.19 -11.34 re S
    %PDF-1.3
    3 0 obj
    <</Type /Page 
    [...]
    >>
    startxref
    556
    %%EOF 
    

    Due to the line "524.41 102.05 48.19 -11.34 re S" any PDF viewer may reject the file as broken. Some viewers, though, do not require the %PDF marker to be the first document line but allow a limitted amount of garbage to precede it. Acrobat Reader on Windows, e.g., merely requires the marker to be in the first thousand bytes or so.

    BTW, the trash line actually looks like a PDF operator for defining a rectangle (which is valid inside stream objects only, not standing alone like here). Maybe there is some command defining a rectangle in your code before the PDF object is properly opened or created?