Free Support Forum - aspose.com

Performance while adding header/footer images

Hi,

We are in the process of evaluating aspose as PDF converter for one of our esteemed client, and working with POCs as of now.

I am trying to add the header/footer images to the pdf generated(i.e. existing pdf) using aspose.pdf for java platform, observed that, its taking much time(apporx 10secs) to put the header/footer images in place.

Please find the below code snippet I am using for the same, review it once and let me know if there is any better way to achieve this with less time consumed.

ImageStamp footerImg = null;
ImageStamp headerImg = null;
//set footer image props
if (pdfInfo.getFooterinputStream() != null) {
footerImg = new ImageStamp(pdfInfo.getFooterinputStream());
footerImg.setBackground(true);
footerImg.setXIndent(2);
footerImg.setYIndent(0);
footerImg.setHeight(60);
footerImg.setWidth(593);
//imageStamp.setRotate(com.aspose.pdf.Rotation.on270);
footerImg.setOpacity(1);
}
//set header imagea props.
if (pdfInfo.getHeaderInputStream() != null) {
headerImg = new ImageStamp(pdfInfo.getHeaderInputStream());
headerImg.setBackground(true);
headerImg.setXIndent(2);
headerImg.setYIndent(778);
headerImg.setHeight(60);
headerImg.setWidth(593);
headerImg.setOpacity(1);
}
//add images in all pages.
for (int i = 1; i <= pdfDocument.getPages().size(); i++) {
if (footerImg != null)
pdfDocument.getPages().get_Item(i).addStamp(footerImg);
if (headerImg != null)
pdfDocument.getPages().get_Item(i).addStamp(headerImg);
}

Hi Shivaji,


Thanks for your inquiry. Please note Aspose.Pdf does not use temporary files for processing but system memory, so you can notice some performance issue in case of large PDF files.

However, we will appreciate it if you please share your sample PDF document as well. So we will look into it and guide you accordingly.

We are sorry for the inconvenience caused.

Best Regards,

Hi,

Thank you for looking in to the concern.

Please find the attached pdf generated with aspose.pdf

In page#4, I am adding the images, its in the format of image and text followed in table format.

after pdf generated, at the end am trying to add headers and footers using the above code provided.

Please review once and suggest me if any better way to achieve this.

Thanks,
Shivaji

Hi Shivaji,


Thanks for your inquiry. I have tested the scenario using you sample code and document with Aspose.Pdf for Java 10.4.1 over Win 7 64 bit and unable to noticed the time lag. It is taking less than 2 seconds to add image header/footer in all five pages. We will appreciate it if you please share some more details and your sample image here as well. So we will try to replicate the issue and will guide you accordingly.

We are sorry for the inconvenience caused.

Best Regards,

Hi,

Thank you for looking in to this issue.

I am attaching here with the code and the analysis I have done.

Found that during creation of imagestamp from inputstream is consuming time.

Please find attached txt file, it contains java code and the output with time displayed in ms.

Please let me know if more details required.

Thanks again!
Shivaji


Hi Shivaji,


Thanks for your inquiry. I have tested the scenario with your code and following are the results. Please share your image here as well, might be it is creating the difference. Moreover, It seems you are evaluating Aspose.Pdf for Java without a license. Please make a request for 30 days temporary license and implement it, it will also improve the processing time.

Entering to addPdfHeaderFooter
Footer time for InputStream added: 649
Footer time for parameters set: 0
after footer from addPdfHeaderFooter: 649
Header time for InputStream added: 23
Header time for parameters set: 0
time after footer header added : 23
Time Taken for page :1 -> 551
Time Taken for page :2 -> 47
Time Taken for page :3 -> 31
Time Taken for page :4 -> 53
Time Taken for page :5 -> 8
Exiting from addPdfHeaderFooter: 1362

We are sorry for the inconvenience caused.

Best Regards,

Hi,

Thank you for the update.

I am using temporary license using the below code.
license.setLicense(new java.io.FileInputStream(“D:\GMU\POCs\AsposeTotalJava\Aspose.Total.Java.lic”));

I am attaching here the images which i am using for the header and footer to render in the pdf file.

Please let me know if more details required on this.

Thanks,

Hi Shivaji,


Thanks for sharing the sample images. I have tested the scenario again and noticed that processing time is increased by almost one second only. Please try the scenario over some other machine and share the results. Please also share your system environment details as well, for further investigation.

Entering to addPdfHeaderFooter
Footer time for InputStream added: 414
Footer time for parameters set: 0
after footer from addPdfHeaderFooter: 414
Header time for InputStream added: 149
Header time for parameters set: 0
time after footer header added : 149
Time Taken for page :1 -> 2004
Time Taken for page :2 -> 14
Time Taken for page :3 -> 26
Time Taken for page :4 -> 69
Time Taken for page :5 -> 15
Exiting from addPdfHeaderFooter: 2691

Best Regards,