Opening a corrupt pdf file freeze the application not throwing exception.

Skip to first unread message


Jun 12, 2014, 6:43:04 PM6/12/14
I am trying to open a pdf that is corrupted (I send it to you in the attachments)! but usually when I found a corrupted file! it simple send an exception!
This pdf doesn't throw and exception and freeze de application. The cursor just stay there indefinitely!

a) How can I detect corrupted files before calling new PDFDoc.
b) How can I set a maximum type of processing and terminate it.
c) Why is not throwing the exception? why it freeze?
using (PDFDoc PDFDoc = new PDFDoc("AttachedCorruptedPDFPath.pdf"))



      decimal TotalPages = PDFDoc.GetPageCount();
235-2012_BAJA VEHICULAR.pdf


Jun 12, 2014, 7:22:36 PM6/12/14
Hello Fraga,

Thank you for letting us know that you're seeing this behaviour.  Could you elaborate on which variant of the PDFNet SDK (from the list at you're using, and what the version of the SDK is?  That way we can investigate the freezing.  Thank you for your help.

Unfortunately, we cannot detect corruption in documents prior to opening them, for performance reasons.  PDF documents can be quite large, and detecting corruption would require analyzing the entire document.


Jun 12, 2014, 7:44:22 PM6/12/14
The version I'am using is

.NET 4.0+

32-bit Windows
PDFTron v4.0.30319


Jun 18, 2014, 2:34:21 PM6/18/14

> a) How can I detect corrupted files before calling new PDFDoc.

You can't. If the document is corrupt beyond repair PDFDoc will throw an exception. To handle corrupt documents simply catch the exception and deal with the file as if it is corrupt (unless the problem is bad path .. to differentiate you could open the doc via Filter first,  or test the error message, ... or verity the path is correct).

Not PDFNet can open many badly damaged and corrupt PDF files. If you would like to find out if the file was auto-repaired (and is therefore damaged) check doc.IsModified() immediately after opening the document.

Btw. I tried to run your code on the provided test file using the current version (
and it works as expected. The issue is that you are not catching the exception. So just surround your code with

try { ... }

catch (PDFNetException e)




Or maybe the issue is that you are using ancient version of PDFNet (v.4.0)... The current version is 6.1.2

> How can I set a maximum type of processing

Not sure what do you mean with this? If you are thinking about time, PDFDoc() will be extremely fast even on huge documents. If you need to guarantee that the line will execute in a specific time span you can open PDFDoc in a separate thread. Btw. if you are using PDFNet for WinRt there are extra utility methods to create document asynchronously (i.e. PDFDoc.CreateAsync...)
Reply all
Reply to author
0 new messages