The code seems fine. Could you please share which JDK version are your using? Also, please share your sample PDF document with us so that we can test the scenario in our environment and address it accordingly.
Please note that the API performance depends upon the size of PDF document as well as its complexity and structure. We used the below code snippet at our end noticed that the conversion time was different in case of each page of the PDF:
try {
Document pdfDocument = new Document(dataDir + "2021毕业生_王宁_平面设计师能力需求数据可视化.pdf");
for (Page page : pdfDocument.getPages()) {
long totalStart = System.currentTimeMillis();
java.io.OutputStream imageStream = new java.io.FileOutputStream(dataDir + "Converted_Image_" + page.getNumber() + ".jpg");
com.aspose.pdf.devices.Resolution resolution = new com.aspose.pdf.devices.Resolution(300);
com.aspose.pdf.devices.JpegDevice jpegDevice = new com.aspose.pdf.devices.JpegDevice(resolution);
jpegDevice.process(page, imageStream);
imageStream.close();
long totalEnd = System.currentTimeMillis();
System.out.println("Page Number=" + page.getNumber() + " Total time taken was " + (totalEnd - totalStart) / 1000 + " seconds for conversion");
}
} catch (Exception ex) {
ex.printStackTrace();
}
Output
Page Number=1 Total time taken was 34 seconds for conversion
Page Number=2 Total time taken was 17 seconds for conversion
Page Number=3 Total time taken was 7 seconds for conversion
Page Number=4 Total time taken was 7 seconds for conversion
Page Number=5 Total time taken was 24 seconds for conversion
Page Number=6 Total time taken was 23 seconds for conversion
Page Number=7 Total time taken was 7 seconds for conversion
Page Number=8 Total time taken was 7 seconds for conversion
Page Number=9 Total time taken was 7 seconds for conversion
Page Number=10 Total time taken was 5 seconds for conversion
Page Number=11 Total time taken was 80 seconds for conversion
Page Number=12 Total time taken was 15 seconds for conversion
Page Number=13 Total time taken was 40 seconds for conversion
Page Number=14 Total time taken was 7 seconds for conversion
Page Number=15 Total time taken was 249 seconds for conversion
Page Number=16 Total time taken was 17 seconds for conversion
Page Number=17 Total time taken was 371 seconds for conversion
Can you please use this code snippet at your side and share the console output with us?