1

I was wondering if is there a way for php to check if a PDF file stored locally on the server is corrupted or not. We have a php application that deals with a lot of scanned documents converted in PDF and it would be nice to check which of them is corrupted to alert the user. I tried to look around but with no luck.

2 Answers 2

1

There are versions of pdflib available which can read PDFs - you could simply try to open and read each page with that.

2
  • Thank you for the answer, I was looking if there could be pure php solution without third part apps. By the way I'll give it a look
    – Simone Magnaschi
    Aug 13, 2009 at 8:59
  • It's not really a 'third part app'... the PDFLib pCOS, at least, is available as a PHP extension. I've used pCOS to analyse PDFs before (inspecting images, embedded fonts etc.). I'm not sure what it would be like detecting 'corruption', but you can definitely test it out for free.
    – Narcissus
    Aug 13, 2009 at 11:24
0

The problem is there are many ways a PDF file can be corrupt.

Maybe your best solution would be to find a PDF reading lib and try to extract the first word from each page or something. That would at least catch some basic types of corruption.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.