Free Support Forum - aspose.com

Problem on certifying a PDF document with multiple pages

Dear Aspose Team,


currently we are trying to certify a PDF document with multiple pages.

From what I’ve found, the way to certify a whole document is like the following.

Despite the fact, that we are using a non-valid certificate for testing, we get the following issues.

On signing a document with a single page, we get a warning about the certificate, but so far it looks valid.

On signing a document with multiple pages, we get an error, that the signature is invalid because the document has undergone changes after it was signed.

But we did not do anything else than the signing procedure.

Could you please shed some light on what might go wrong?

Tested with Aspose.Pdf version 10.6.0.0.

I have attached the resulting multi-page document as well as the signed single-page document and the related source documents.

public void SignPdfDocumentTest()
{
       <span style="color:#57a64a;">//string sourcePdfPath = rootFolder+@"\signpdf\pdfToSign.pdf";</span>

       <span style="color:#569cd6;">using</span> (<span style="color:#4ec9b0;">Document</span> document <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> <span style="color:#4ec9b0;">Document</span>(sourcePdfPath))
       {
           <span style="color:#569cd6;">using</span> (<span style="color:#4ec9b0;">PdfFileSignature</span> signature <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> <span style="color:#4ec9b0;">PdfFileSignature</span>(document))
           {
               <span style="color:#4ec9b0;">PKCS7</span> pkcs <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> <span style="color:#4ec9b0;">PKCS7</span>(pkcs7CertPath, <span style="color:#d69d85;">""</span>); <span style="color:#57a64a;">// Use PKCS7/PKCS7Detached objects</span>
               <span style="color:#4ec9b0;">DocMDPSignature</span> docMdpSignature <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> <span style="color:#4ec9b0;">DocMDPSignature</span>(pkcs, <span style="color:#b8d7a3;">DocMDPAccessPermissions</span><span style="color:#b4b4b4;">.</span>AnnotationModification<span style="color:#b4b4b4;">|</span><span style="color:#b8d7a3;">DocMDPAccessPermissions</span><span style="color:#b4b4b4;">.</span>FillingInForms);
               System<span style="color:#b4b4b4;">.</span>Drawing<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">Rectangle</span> rect <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> System<span style="color:#b4b4b4;">.</span>Drawing<span style="color:#b4b4b4;">.</span><span style="color:#4ec9b0;">Rectangle</span>(<span style="color:#b5cea8;">0</span>, <span style="color:#b5cea8;">0</span>, <span style="color:#b5cea8;">0</span>, <span style="color:#b5cea8;">0</span>);
               <span style="color:#57a64a;">//set signature appearance</span>
               signature<span style="color:#b4b4b4;">.</span>SignatureAppearance <span style="color:#b4b4b4;">=</span> SigLogoPath;
               <span style="color:#57a64a;">//create any of the three signature types</span>
               signature<span style="color:#b4b4b4;">.</span>Certify(document<span style="color:#b4b4b4;">.</span>Pages<span style="color:#b4b4b4;">.</span>Count, <span style="color:#d69d85;">"reason"</span>, <span style="color:#d69d85;">"contact"</span>, <span style="color:#d69d85;">"location"</span>, <span style="color:#569cd6;">false</span>, rect, docMdpSignature);
               <span style="color:#57a64a;">//signature.CoversWholeDocument(signature.);</span>
               <span style="color:#57a64a;">//save output PDF file</span>
               signature<span style="color:#b4b4b4;">.</span>Save(targetPdfPath);
           }
       }


   }</pre><pre style="background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><span style="background-color: rgb(255, 255, 255);"><font face="Times New Roman">Thanks and kind regards

Wolfgang

Hi Wolfgang,


Thanks for your inquiry. I have tested scenario using a sample certificate and unable to notice and warning or error. I will appreciate it if you please share your certificate here, so we can test the scenario and share our findings accordingly.

We are sorry for the inconvenience caused.

Best Regards,