origin
origin

Reputation: 128

How to convert PDF-files to PNG-images concurrently?

I have a scenario, where I need to convert multiple PDF-files to PNG-images concurrently. Although it can be doable using Java 8 Parallel Streams, I need it to be executed on Java 7.

This is the snippet which I use to convert PDF to PNG without parallel processing and by using PDFBox.

PDDocument document = PDDocument.load(new File(pdfFilename));
PDFRenderer pdfRenderer = new PDFRenderer(document);
for (int page = 0; page < document.getNumberOfPages(); ++page)
{ 
   BufferedImage bim = pdfRenderer.renderImageWithDPI(page, 300, ImageType.RGB);
   ImageIOUtil.writeImage(bim, pdfFilename + "-" + (page+1) + ".png", 300);
}
document.close();

Kindly, please suggest some approach to tackle this.

Upvotes: 0

Views: 491

Answers (0)

Related Questions