I have an issue with multiple pdf signatures. My Aspose version is 22.5.0.
The issue is that, when the original file is a .pdf, then the signatures get invalidated most of the time. So only the last one is valid, others are not.
This issue does not present itself, when the original file is not a .pdf file. For example if I transform from .doc to .pdf and then sign multiple times, signatures are all valid.
I have tried different formats and different ways of converting/signing, but have not been able to solve this problem.
I am using an external signature component, that works in a way, that this should not happen as is noticed in the example of multiple signatures being valid in the case, when the original is not a .pdf file. But there is something different with .pdf to .pdf conversion or so it seems.
I would appreciate your help.
Not sure what other info you require, but will provide upon request.
It appears you are encountering issues with multiple signatures becoming invalid when converting from PDF to PDF using Aspose. This can occur because any modification to a PDF, including signing, can impact the integrity of existing signatures.
When you sign a PDF, the signature is linked to the document’s content at that specific moment. If the document is altered afterward (even by adding another signature), it can invalidate previous signatures. This behavior differs from converting formats like DOC to PDF, where the signing process may manage the document structure differently.
To troubleshoot this issue, consider the following steps:
Ensure Proper Signing Order: Verify that you are signing the document in the correct sequence and that each signature is applied without modifying the previous ones.
Utilize the PdfFileSignature Class: Use the PdfFileSignature class to effectively manage signatures. This class allows you to verify existing signatures and ensure they remain valid after each operation.
Monitor Document Modifications: After adding each signature, check for any modifications to the document that could potentially invalidate previous signatures.
Consult the Documentation: For more detailed guidance, refer to the official Aspose documentation on managing PDF signatures.
If the problem persists, consider reaching out to Aspose support for more specific assistance tailored to your version and use case.
After further analysis I have a few answers for the points provided.
The signing order is proper.
Not sure how I would utilize this class as the signature component is external and signatures remain valid even when other file types are converted to pdf. So pdf2pdf conversion is most likely the issue.
There are a few modifications, specifically the signed file gets saved, but if this were the issue, then it should not have worked in any case. But this case where signatures get invalidated is the exception, not the rule.
I have consulted the documentation, but my case is different, since the signing component is external.
So I am sorry, but not sure what I can do in this case.
If possible, can you please share sample code snippet with sample PDF document(s) which we can use to replicate the scenario in our environment? We will test the scenario and address it accordingly.
protected override byte[] ConvertFromBytes(byte[] byteArray, ConversionOptions conversionOptions = null)
{
var signableFormats = new[] {
PdfFormat.PDF_A_1B,
PdfFormat.PDF_A_2B,
PdfFormat.PDF_A_3B
};
using (MemoryStream stream = new MemoryStream(byteArray))
{
using (MemoryStream outStream = new MemoryStream())
{
Document doc = new Document(stream);
//Check if the PDF already contains digital signature
foreach (Field field in doc.Form)
{
if (field is SignatureField sigField && sigField.Signature != null)
{
// Already has signature, return original bytes
return byteArray;
}
}
// Check if the PDF is already in a signable PDF/A format
if (signableFormats.Contains(doc.PdfFormat))
{
// Already compliant, return original bytes
return byteArray;
}
// Save the document to stream.
doc.Convert(new MemoryStream(), PdfFormat.PDF_A_2B, ConvertErrorAction.Delete);
doc.Save(outStream);
// Convert the document to byte form.
return outStream.ToArray();
}
}
These are the PDF files I have tested. And the “picture_only.pdf” one works correctly. The other two do not.
I have attached the signed files below as well.
The “picture_only (2).pdf” is the file that works. The other two have invalid signatures. And I am unsure what is the difference between them.