validate pdf

  • Thread starter Thread starter eddiec
  • Start date Start date
E

eddiec

Hi,

Is there any way in C# to validate if a PDF is in legal PDF format or
if it is corrupt.

cheers,

eddiec :-)
 
Is there any way in C# to validate if a PDF is in legal PDF format or
if it is corrupt.

You could try {} to open the file with an iTextSharp.text.pdf.PdfReader[1]
an see if it throws any exceptions.

Pulling in a fat library like iTextSharp might be a bit drastic though,
but usually in such system you would need to do some work on the PDF file
at some point.

Another approach would be to manually read the first few bytes of the
file, and match them agains the header defined in PDF specs. This would
require no external libraries, but the check is not as thorough.

[1] http://itextsharp.sourceforge.net/
 
eddiec said:
Is there any way in C# to validate if a PDF is in legal PDF format or
if it is corrupt.

I'm always surprised by questions like this. Under what conditions would
you receive a supposed PDF file, when it isn't really a PDF file?
 
I'm always surprised by questions like this.  Under what conditions would
you receive a supposed PDF file, when it isn't really a PDF file?

We've converted 500,000 files from AFP to PDF and some are corrupt

Thanks for all the answers

cheers,

eddiec :-)
 
Back
Top