Test if a PDF is a valid file in PHP

Hi guys,

I have a system that manipulates PDFs in a workflow. Every now and then a corrupt PDF causes the script I have processing the PDFs from working.

Does anyone know of a way of determining if a PDF is corrupt or not? It could be an external script called from PHP if necessary (I'm running Centos 7 x64 and PHP 5.4.16).

cheers

Posted Jul 31, 2018, 1:31 PM UTC

23
CODESIGN2•

check

  • extension
  • magic header
  • page dimensions
  • page-count

If those check out it is pretty certain its a valid pdf.

Alternatively run a cli PDF utility and scan for exit code.

2