views:

46

answers:

1

Hi-- I'm seeing some strange behavior from some dynamically generated PDFs using the TCPDF library in PHP.

Standard lamp stack-- however, if you try to open the PDF from Windows with Acrobat Reader, it gives an error that the "file is damaged and could not be repaired". From Mac, Linux, etc. the file works fine, and opens fine. It also opens fine in Google Docs-- so clearly the PDF itself is ok.

Is it possible that the mime type (application/pdf) is causing problems in Windows?

Thanks

A: 

What browser on Windows? All? Or just one? My initial gut instict, is that the Windows browser is ignoring the encoding IF the content is being gzipped (Ignoring the Content-Encoding header). That's if you're even sending that header.

Open the file you downloaded in some text editor (Notepad, etc). The first few characters of the file should be %PDF-1. with another number after it. If it's not at the beginning, check to see if the file is gzipped (rename the file to blah.gz, and then run it through gzip to try to decode it). If that worked, then your problem is the browser ignoring the encoding.

IF it is ignoring the encoding, you need to not gzip the output of that PHP file. How you do that will depend on your server configuration.

Oh, and the application/pdf is the proper mime type. And the mime type is not your problem, since Acrobat is at least trying to open the file...

ircmaxell
Thanks ircmaxwell-- the first line is %PDF-1.5Does that make a difference?
julio
Well, that means it's not an encoding error. That's a valid header. Have you tried asking TCPDF about the problem (reporting it as a bug, or checking their website)?
ircmaxell
no, since I was assuming at this point it's a server issue, since some servers serve the same PDF with no issues to the same Win/Acrobat system.
julio
Well, start by trying to see what's different between the servers (PHP version, installed extensions, etc). Check the error logs on the erroring server to see if perhaps errors are being thrown that may be causing it...
ircmaxell