0

I have a PHP app running the PDFlib program to generate PDFs. Version 6 has been running fine for a long time. We are about to change servers and decided to upgrade to the latest version of all of the software.

Well, the parts of the program that use PDFlib to create PDFs now makes PDFs that Acrobat thinks are "Corrupt and can not be repaired." Strangely, Firefox opens the file using the Adobe plugin just fine. So does the generic Ubuntu PDF viewer. But when I download the PDF and try to open it in Acrobat Reader or the full blown Acrobat it says that the file is corrupt and cannot be repaired.

Has anyone seen this before, or do you know where I should start looking? The fact that Firefox and Ubuntu can read it tells me that it can't be THAT corrupt. In fact it looks perfectly fine to those readers with all of the graphics and different colored text and fonts and everything. It has to be something stupid.

EDIT:

Ok, I stripped down the PHP file generating the bad PDF to nothing but "Begin Document", "Begin Page", "End Page", "End Document" and got no errors. Then I added in one of the background image loads and found the first problem.

$bgImageUrl = $_SERVER['DOCUMENT_ROOT'] ."path/to/fadedBG2.png"; 
$bgImageData = file_get_contents($bgImageUrl); 
$p->create_pvf("/pvf/bgImageData", $bgImageData, ""); 
$bgImage = $p->load_image("auto", "/pvf/bgImageData" , "");

That last line is causing corruption in the file. I pretty much copied this code directly from the pdfLib web site so I'm not sure what's going on here.

  • You say it happens when you download the file, but can open the file. Is this download via browsers? Because the error sound more to me to be a browser related than pdflib. If the pdf itself was corrupt - you shouldn't be able to open it at all. Can you open it directly on the machine it was build without any issues? – Allan S. Hansen Jan 19 '15 at 19:57
  • Hi, Allan. Thanks for answering. If Firefox is set to open PDFs using the Adobe plugin then it opens just fine and looks perfect. If I download the file and try to open it with Adobe Acrobat or Adobe Reader in Windows then I get the "corrupt and cannot be repaired" error. If I download the file to Ubuntu and open it with the generic PDF reader installed by default on Ubuntu then it opens just fine. So it only seems to be a problem with Acrobat for some reason. But I need that to work. I might download an invoice and email it and if the customer can't read it, that's a problem. – Mark J. Marshall Jan 19 '15 at 20:01
  • I think @Allan's point was that downloading it might be adding some corruption that Ubuntu and Firefox tolerate. Can you run this generation locally, save the PDF to disk, and then try to load it (i.e. so it does not travel via HTTP at all)? Worth a try, to narrow things down? – halfer Jan 19 '15 at 20:39
  • I'm trying to figure out why you removed the "Thank You" from my question. I'm also trying to figure out how an https transfer of a file generated with version 9 of the software would corrupt the file being transferred when that same process doesn't corrupt a file generated with version 6 of the software. – Mark J. Marshall Jan 19 '15 at 22:04
  • If you take the file directly from the server/machine that build the pdf - not download via browser, but a simple file copy - does Acrobat still complain? – Allan S. Hansen Jan 20 '15 at 06:22
  • you might check, if the load_image() failed. If so, retrieve the error message. You might also enable the PDFlib logging for such run, and open a support case at support@pdfliib.com (http://www.pdflib.com/licensing-support/opening-a-support-case/) and attach the log file along with the wrong output PDF – Rainer Jan 20 '15 at 10:18

1 Answers1

0

Thanks to some support folks, I found a way to make this work. Adding a "compatibility=1.4" to the begin_document() call like this:

$p->begin_document("", "compatibility=1.4")

Solves the issue.

According to the pdflib support folks, lots of stuff changed in the PDF format between versions of the software. So adding that compatibility directive forces the program to keep the PDF backwards compatible.