Optimus
Optimus

Reputation: 65

PDF validate using PDFBOX PreflightParser for PDDocument

I could like to validate the pdf that was created(not as a file) but as ByteArrayOutputStream which is downloaded to browser . In order to avoid security issue could like to validate using pdfbox preflightparser where it has option only for parsing file not PDDocument.

ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
doc.save(byteArrayOutputStream);
PreflightParser parser = new PreflightParser(doc);

//this constructor accepts only file.

Expectation is validate pdf file on the fly instead of loading from system.

Upvotes: 1

Views: 3348

Answers (2)

Tilman Hausherr
Tilman Hausherr

Reputation: 18851

You can also pass a DataSource. To facilitate this, use org.apache.pdfbox.io.IOUtils.ByteArrayDataSource whose constructor accepts an InputStream.

Upvotes: 2

Deltharis
Deltharis

Reputation: 2373

If you don't need extra information PreflightParser can give you - you can use PDFParser. It's constructor accepts RandomAccessBuffer which takes byte[] to create.

Upvotes: 0

Related Questions