PDF with jpeg2000 compression takes a lot longer to convert to image than the ones without jpeg2000

Dear Aspose Support Team,

PDF with jpeg2000 compression take a lot longer (~10-15 times more depending on the environment) to convert to image than PDF without jpeg2000 compression using following code snippet:

  public static void getImageFromPdf(String soucePath, String destinationPath, int totalPdfPages)
      throws Exception {
    System.out.println("Start: getImageFromPdf()");
    InputStream pdfFileInputStream = new FileInputStream(soucePath);
    com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(pdfFileInputStream);
    FileOutputStream outStream = null;
    int startPage = 1;
    String[] imageFormats = {"JPG", "JPEG"};
    long beginTime = System.currentTimeMillis();
    for (String imageFormat : imageFormats) {
      File file;
      for (int i = startPage; i <= totalPdfPages; i++) {
        file = new File(destinationPath + i + "-" + imageFormat + "." + imageFormat);
        outStream = new FileOutputStream(file);
        byte imagesBytes[] = convertToImage(pdfDocument, imageFormat, "", i, -1, 300);
        outStream.write(imagesBytes);
        outStream.flush();
        outStream.close();
      }
    }
    long endTime = System.currentTimeMillis();
    System.out.println("Total Time Taken: " + (endTime - beginTime) / 1000 + "Seconds");
    pdfFileInputStream.close();
    System.out.println("End: getImageFromPdf()");
  }

  public static byte[] convertToImage(com.aspose.pdf.Document pdfDocument, String imageFormat,
      String password, int pageNum, int imageType, int resolution) throws Exception {
    System.out.println("Start: convertToImage()");
    byte[] imageBytes = null;
    Resolution resolutionObj = new Resolution(resolution);
    ByteArrayOutputStream imageStream = new ByteArrayOutputStream();
    try {
      switch (imageFormat.toUpperCase()) {
        case "JPEG":
        case "JPG":
          JpegDevice jpegDevice = new JpegDevice(resolutionObj, 50);
          jpegDevice.process(pdfDocument.getPages().get_Item(pageNum), imageStream);
          System.out.println("Returning Byte Array Size: " + imageStream.toByteArray().length);
          imageBytes = imageStream.toByteArray();
          break;
        default:
          throw new Exception("Image format not supported");
      }

    } finally {
      // closePdf(pdfDocument);
    }
    System.out.println("End: convertToImage()");
    return imageBytes;
  }

Claims.pdf (946.3 KB)
ClaimsFull.pdf (2.8 MB)

The attached PDF (Claim.pdf) is with jpeg2000 compression, PDF (ClaimFull.pdf) is without jpeg2000 compression.
Could you please suggest a better solution/workaround to improve this?

Regards,
Madhurendra Narayan Tiwary

@edleads

We were able to notice the difference of conversion time while testing the scenario with Aspose.PDF for Java 20.9 in our environment. Therefore, we have logged an issue as PDFJAVA-39854 in our issue tracking system for further investigation. We will look into its details and keep you posted with the status of ticket resolution. Please be patient and spare us little time.

We are sorry for the inconvenience.

Dear Support Team,

Do we have any update on this ticket?
It’s been a while. :slight_smile:

Regards

@edleads

Regretfully, the earlier logged ticket could not get resolved due to other pending issues in the queue logged prior to it. However, we will surely inform you as soon as we make some significant progress issue resolution. We highly appreciate your patience and comprehension in this regard.

We apologize for the inconvenience.