Free Support Forum - aspose.com

Digital Signature PKCS1 - Show Signature in all the Pages of the Signed PDF

Dear Team,



There is a requirement in our company for Digitally Signing a PDF Document and displaying the Signature in all pages of the Signed PDF Document.



Using current methods, we can display the signature in all the pages.

However only the digital signature in the last page is shown as VALID while all the signatures before that is shown as INVALID (Document altered).



Can we overcome this obstacle using ASPOSE PDF API?

Hi Balakrishna,


Thanks for your patience.

Can you please share your code snippet and resource files, so that we can test the scenario in our environment. We are sorry for this inconvenience.

Hi,



Please find the code below

------------------------------------------------





Sub Main()

Dim dataDir As String = “D:”



'Import PDF Document

Dim pdfdoc As New Document(dataDir & “input.pdf”)



'create PdfFileSignature object and choose input document

Dim pdfSign As New PdfFileSignature(pdfdoc)

'create a rectangle for signature location

Dim rect As New System.Drawing.Rectangle(100, 100, 200, 100)

'create signature

Dim signature As New PKCS1(“pfxfilename.pfx”, “passwd”)



'Sign

For i As Integer = 1 To pdfdoc.Pages.Count

If i > 4 Then

Exit Sub

End If



pdfSign.Sign(i, “Signature Reason”, “Contact”, “Location”, True, rect, signature)

pdfSign.Save(dataDir & “output.pdf”)

pdfSign.Close()

pdfSign = New PdfFileSignature(dataDir & “output.pdf”)

Next

End Sub



------------------------------------------------------

Hi Balakrishna,


Thanks for sharing the code snippet.

I have tested the scenario using one of my sample Signature file and PDF document where I have used following code snippet and as per my observations, the signature validity is shown as Unknown instead of Invalid. Can you please share your resource files, so that we can again test the scenario in our environment. We are sorry for this inconvenience.

[VB.NET]

Dim dataDir As String = “c:\pdftest”<o:p></o:p>

'Import PDF Document

Dim pdfdoc As New Document(dataDir & "Concatenated_output.pdf")

'create PdfFileSignature object and choose input document

Dim pdfSign As Aspose.Pdf.Facades.PdfFileSignature = New Aspose.Pdf.Facades.PdfFileSignature(pdfdoc)

'create a rectangle for signature location

Dim rect As New System.Drawing.Rectangle(100, 100, 200, 100)

'create signature

Dim signature As New Aspose.Pdf.InteractiveFeatures.Forms.PKCS1("c:/pdftest/MySPC.pfx", "test")

'Sign

For i As Integer = 1 To pdfdoc.Pages.Count

If i > 4 Then

Exit Sub

End If

pdfSign.Sign(i, "Signature Reason", "Contact", "Location", True, rect, signature)

pdfSign.Save(dataDir & "Signed_output.pdf")

pdfSign.Close()

pdfSign = New Aspose.Pdf.Facades.PdfFileSignature()

pdfSign.BindPdf(dataDir & "Signed_output.pdf")

Next