We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to parallel image-rendering

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?

Hi.

On a multi core machine the best and probably only way is split the pdf into single page pdfs then convert each one in parallel. Even with the cost of splitting, on a half decent machine this will be faster.

The issue is the aspose dll only allows one thread at a time to access the source pdf file so parallel threads give no speed bost so only option is to split and work on the single page pdfs files.

Si

@KHd

Thank you for contacting support.

We have logged an investigation ticket with ID PDFJAVA-37948 in our issue management system. The ticket ID has been linked with this thread and we will notify you as soon as some significant updates will be available in this regard.

Thanks a lot! Good to know that there is at least a possibility to speed things up.

@KHd

You may try suggested approach in the meanwhile and we will share our findings with you as soon as the ticket will be investigated in our environment.