Hey there,
I wanna parallel image-rendering like @simon.fairey already asked in his request " Is there a solution for the Parallel.ForEach issue processing a PDF".
This is the code I want to run parallel:
public synchronized List<byte[]> renderImage(String htmlStringtoRenderImage, Integer pDpi)
throws RuntimeException {
List<byte[]> renderedImages = new ArrayList<>();
try {
HtmlLoadOptions htmlLoadOptions = new HtmlLoadOptions();
htmlLoadOptions.setInputEncoding(“UTF-8”);
PageInfo pageInfo = htmlLoadOptions.getPageInfo();
pageInfo.setWidth(pageInfo.getWidth() * 2);
pageInfo.setHeight(pageInfo.getHeight() * 2);
Document pdfDoc = new Document(
new ByteArrayInputStream(htmlStringtoRenderImgae.getBytes(Charset.forName("UTF-8"))), htmlLoadOptions);
for (Page page : pdfDoc.getPages()) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
Resolution resolution = new Resolution(pDpi);
PngDevice pngDevice = new PngDevice(resolution);
pngDevice.process(page, os);
renderedImages.add(os.toByteArray());
}
} catch (Exception e) {
throw new RuntimeException("Couldn't render image", e);
}
return renderedImages;
}
Are there any solutions for this issue?