Alex Rivera | Logout

How can I determine if a file is a PDF file?

Asked 2009-06-02T20:44:33.223
41

I am using PdfBox in Java to extract text from PDF files. Some of the input files provided are not valid and PDFTextStripper halts on these files. Is there a clean way to check if the provided file is indeed a valid PDF?

Edit
Report

1 Answer

4

Pdf files begin "%PDF" (open one in TextPad or similar and take a look)

Any reason you can't just read the file with a StringReader and check for this?

answered 2009-06-02T21:15:33.800

Your Answer