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

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”))

{

PDFDoc.InitSecurityHandler();

decimal TotalPages = PDFDoc.GetPageCount();
}

235-2012_BAJA VEHICULAR.pdf (52 KB)

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 http://www.pdftron.com/pdfnet/downloads.html) 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.

The version I’am using is



.NET 4.0+

32-bit Windows

PDFTron v4.0.30319

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 (http://www.pdftron.com/pdfnet/downloads.html)
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)

{

Console.WriteLine(e.Message);

}

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…)