Possible Duplicate:
Detect if PDF file is correct (header PDF)
I want to validate that the data in a FileStream
instance represents a valid PDF document. Specifically, I need to know that Adobe Reader will be able to successfully open the file.
Can anyone recommend an open source library or best practice for this task?
Take a look at iTextSharp , it should give you what you need.
EDIT:
I know it's bad practice to use exceptions to control flow, but you could do this:
public bool IsValidPdf(string fileName)
{
try
{
new iTextSharp.text.pdf.PdfReader(fileName);
return true;
}
catch (iTextSharp.text.exceptions.InvalidPdfException)
{
return false;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With