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