Free Support Forum - aspose.com

Evaluating to buy - how to validate?

We need the ability in our J2EE applicaiton to validate the document a user has uploaded. The word stuff works fine - if you try to create a Document(...) on something that isn't a good word document, it fails with an exception. However, you can create a PdfExtractor on anything and it doesn't fail. Is there a way with the pdf kit to validate that you have a valid pdf passed in? I don't want to search for text, because the PDF may or may not have text in it.
Gary Furash (furashg@mcao.maricopa.gov)

Currently the validity inspection is processed when you call the functional api, such as PdfExtractor.extractText(), you will get an error written “Getting pdf version error” if you pass non-pdf format document as parameters. We will consider you practical advice and wish to support in the near future release.

Here's a sample file. If I do the following
fileName = "goodPdfDocument.pdf";
hasText = false;
hasImage = false;
try {
PdfExtractor extractor = new PdfExtractor();
extractor.bindPdf(fileName);
// the extractor doesn't do any validation until you try to do
// something with it
extractor.extractText();
extractor.extractImage();
print("Document " + fileName + " validated successfully");
} catch(Exception e) {
print("Problem with " + fileName + ": " + e.getMessage());
}
it says it's fine, but in reality its gibberish. I've attached the example document. If you try to open it with adobe reader, reader fails.
(Note: above is in beanshell. Should work the same as java)
Ignore. My fault. You're right - it throws an exception.