How do I detect corrupt PDF files and gracefully deal with processing errors?

Q: How would you recommend gracefully handling corrupted pdf files in our application?
Can we detect these corrupted files in code, so we can inform the user?

Interestingly Adobe Acrobat doesn’t render this pdf at all, whereas in PDFNet it does

In this particular case, the pdf can be viewed with PDFNet, but when the user tries to annotate (using our custom annotation) the PDFNetException is thrown.

It appears that PDFNet can handle some corrupted files, in some ways better the Adobe Acrobat.

A: Unfortunately these days, many/most? files out there are invalid (due to buggy PDF creators and processors) in one way or another. PDFNet (like Acrobat) can process many malformed or damaged files. There are some utilities (such as pdftron.PDF.PDFA.PDFACompliance) that could be used to list potential issues with the file, however full validation is slow and is probably of limited use unless you need to make sure that your files are PDF/A compliant.

Both PDFDraw and PDFView include SetErrorReportProc() callback that could be used to report non-fatal errors that occur during page rendering/processing. If a fatal processing error occurs, an exception will be thrown. In this case you can also catch the error, and inform the user about the issue.