We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How do I confirm the file format?

I am seeing InvalidFileFormat exceptions and my execution stops. How may I test a file format before handing it to your conversion tool? Is there a trick to catching run-time eceptions?

Hi there,


Thanks for your inquiry. You may use following code snippet for the purpose. Hopefully it will help you to accomplish the task.

IsCorrupt(myDir + “corrupt_hang.pdf”);<o:p></o:p>

....

....

private static bool IsCorrupt(string path)

{

try

{ Document doc = new Document(path); }

catch (Exception ex)

{ return true; }

return false;

}

Please feel free to contact us for any further assistance.


Best Regards,

Hi,


Adding more to Tilal’s comments, you can also determine if the input file is a valid PDF or not by using following code line.

[C#]

try<o:p></o:p>

{

Console.WriteLine(new PdfFileInfo("").IsPdfFile);

}

catch (Exception ex)

{ return true; }

return false;

Hi there,


Thanks for your feedback. It is good to know that information help you to accomplish your requirements.

Please keep using our API and feel free to ask any question or concern. We will be more than happy to extend our support.

Best Regards,