1
votes

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.

2

2 Answers

2
votes

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

0
votes

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.