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

Free Support Forum - aspose.com

Putting a jpeg image in a pdf- it takes more than 4 second

I put a jpeg file in a pdf and it takes more than 4 seconds to complete.

Is there anyway to make it performance better?

Here is the code:
public static void embeddedImageInPdf(String imagefile, String out) {
Document document = null;
try {
long currtime = System.currentTimeMillis();
Image image = new Image();
image.setFile(imagefile);
document = new Document();
addImageToPdf(document, image);
document.save(out);
LOGGER.info("Time to embed an image " + imagefile + " takes " + (System.currentTimeMillis() - currtime) + “ms”);
} catch (Exception e) {
LOGGER.error(“Error in creating writer:”, e);
} finally {
if (document != null) {
document.close();
}
}
}


protected static void addImageToPdf(Document document, Image image) throws Exception {
Page p = document.getPages().add();
p.getParagraphs().add(image);
}

Hi There,


Thanks for contacting support.

Please note Aspose.Pdf process files in memory so performance depends upon the file size and system resources. I have tested the scenario with smaller file i.e. 10 KB, and it took only 1459ms to aadd the image into the PDF file.

I have also tested the scenario with 10 MB JPG file and it took 6002ms to add the image into the PDF file. So, time will vary from file to file depending upon the size and the system resources.

If you need further assistance, please feel free to contact us.

Best Regards,
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco} p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco}

Is that the best Aspose can do? inserting a single image in a 10K pdf in 1.4 seconds?? So creating a 1000 page pdf will take 1400 seconds - 23minutes???


In our testing, the open source version of iText inserts an image into a pdf in 84ms on average - using the same hardware and test system where Aspose took an average of 3813ms. Either there is something wrong with our use of Aspose, or there is a significant defect in Aspose that would cause your system to take 45 times longer than a 5 year old open source product. Please respond with your plans to address the SIGNIFICANT performance issue.

Hi There,


I created a folder having 1,000 files of 10K each and I run the following code snippet and I was able to add these 1000 images in 26 seconds. I have also attached the resultant PDF file for your reference.

JAVA

String dataDir = “/Users/fahadadeel/Downloads/resources/”;
final File folder_name = new File(dataDir + “small_images”);
long currtime = System.currentTimeMillis();
Document document = new Document();
for (final File child : folder_name.listFiles()) {
Page new_page = document.getPages().add();
String image_name = child.toString();
Image image = new Image();
image.setFile(image_name);
new_page.getParagraphs().add(image);
document.processParagraphs();
}
document.save(dataDir + “outputfile.pdf”);
System.out.println("Time to embed folder " + folder_name + " takes " + (System.currentTimeMillis() - currtime) + “ms”);

Moreover, I have tested the scenario with a folder having 1024 files of your provided image and I was able to add these images in 52 minutes. For the sake of performance improvement, I have logged a ticket PDFJAVA-36590 in our issue tracking system. We will further look into it and will keep you updated within this forum thread. Please be patient and spare us little time.

We are sorry for this inconvenience.

Best Regards,