Hello team,
We need to sign digital signatures for all pages of pdf files with > 100 pages, and followed your instruction in How to digitally sign PDF|Aspose.PDF for Java
However, we found that it’s too slow + consume too much memory, and it’s actually crash the app.
We also see that PdfFileSignature.save() is extremely slow, we’re not sure what to do to boost the speed.
So what is the best practice to handle this scenerio, in faster and lower resource usage?
Thanks,
Nick
@WaseemMuthu
To efficiently sign digital signatures for all pages of a PDF document with more than 100 pages, while minimizing memory usage and improving speed, consider the following best practices:
-
Batch Processing: Instead of signing each page individually, process the PDF in batches. This can significantly reduce the overhead associated with multiple calls to the signing method.
-
Use PdfFileSignature Class: Utilize the PdfFileSignature
class, which is specifically designed for signing PDF files. This class provides methods that can help streamline the signing process.
-
Optimize Signature Appearance: If you are using a custom appearance for the signature, ensure that it is optimized. Avoid unnecessary graphics or large images that can increase memory consumption.
-
Avoid Repeated Save Calls: If you are calling PdfFileSignature.save()
multiple times, try to minimize these calls. Instead, make all necessary modifications and save the document once at the end of the signing process.
-
Use Timestamps Wisely: If you are adding timestamps to your signatures, ensure that you are using a reliable timestamp server. This can help in reducing the time taken for the signing process.
-
Profile Your Application: Use profiling tools to identify bottlenecks in your application. This can help you understand where the most memory is being consumed and where the slowdowns are occurring.
-
Consider Asynchronous Processing: If your application allows, consider implementing asynchronous processing for signing. This can help keep the application responsive while the signing operation is being performed.
Here is a simple code snippet demonstrating how to sign a PDF using the PdfFileSignature
class:
import com.aspose.pdf.*;
public class SignPdf {
public static void main(String[] args) {
// Load the PDF document
Document pdfDocument = new Document("input.pdf");
PdfFileSignature pdfSign = new PdfFileSignature(pdfDocument);
// Loop through all pages to sign
for (int pageIndex = 1; pageIndex <= pdfDocument.getPages().size(); pageIndex++) {
// Sign each page
pdfSign.sign(pageIndex, "signatureFieldName", "path/to/certificate.pfx", "password", "Signature Reason", "Location", "Contact Info");
}
// Save the signed document
pdfSign.save("signed_output.pdf");
pdfSign.close();
}
}
By following these practices, you should be able to improve the performance of your application when signing large PDF documents. If you continue to experience issues, consider reaching out to the Aspose support team for further assistance.
This generated answer throw an error:
image.png (32.9 KB)
com.aspose.pdf.exceptions.PdfException: Several signatures can’t be placed at once. Please, after each Sign invoke Save.
@WaseemMuthu
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): PDFJAVA-44781
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
1 Like
So could you please check if this needs improvement on your product? Or we can have solution for our application?
Currently, there seems to be a slowdown when applying an Aspose digital signature to PDF documents with more than 100 pages. Could you confirm if the fix you mentioned is intended to improve performance when signing large PDF files?
@WaseemMuthu
Usually the performance of the API depends upon many factors like PDF file size, environment in which the API is being used as well as structure and complexity of the document it is processing. The ticket has been logged to analyze the API performance with sample PDF files and we definitely intend to improve it in such cases where digital signatures are added to 100s of file in single operation. It will also be helpful for us if you could please share one of your sample PDF file so that we can include it in our investigation as well.
Hi , please find the attached pdf with more than 100 pages.
sample file.pdf (1.5 MB)
@WaseemMuthu
Thanks for the sample file. We have attached it with the logged ticket for investigation. We will prioritize it on first come first serve basis and as soon as we make some progress towards ticket resolution, we will inform you. Please be patient and spare us some time.
We are sorry for the inconvenience.