good night,
I am working with itextsharp and want to remove the digital signatures from the document. I want to remove them not flatten them.
I found this code to flatten, what would be the variant to delete the signature.
I will appreciate any help.
Observation: I do not have the name of the signature field, it must be removed from any signed document.
Thanks a lot,
I'm working with visual studio 2019 and itextsharp 5.5.13.2
Greetings.
Protected Sub ManipulatePdf(ByVal dest As String)
Dim pdf As PdfReader = New PdfReader(SRC)
Dim stamper As PdfStamper = New PdfStamper(pdf, New FileStream(dest, FileMode.Create, FileAccess.Write, FileShare.None))
stamper.FormFlattening = True
stamper.Close()
End Sub
Public Shared ReadOnly DEST As String = "c:\temp1\2.pdf"
Public Shared ReadOnly SRC As String = "c:\temp1\1.pdf"
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim file As System.IO.FileInfo = New System.IO.FileInfo(DEST)
file.Directory.Create()
ManipulatePdf(DEST)
End Sub
Code update to find and remove signatures, not working yet.
Protected Sub ManipulatePdf(ByVal dest As String)
Dim pdf As PdfReader = New PdfReader(SRC)
Dim acro As AcroFields = pdf.AcroFields
Dim stamper As PdfStamper = New PdfStamper(pdf, New FileStream(dest, FileMode.Create, FileAccess.Write, FileShare.None))
Dim nombrfirma As List(Of String) = acro.GetSignatureNames()
For Each firma As String In nombrfirma
Dim signature As AcroFields.Item = stamper.AcroFields.GetFieldItem(firma)
For i = 0 To i < signature.Size
signature.GetWidget(i).Clear()
signature.GetMerged(i).Clear()
signature.GetValue(i).Clear()
i += 1
Next
Next
'stamper.FormFlattening = True
stamper.Close()
pdf.Close()
End Sub
Public Shared ReadOnly DEST As String = "c:\temp1\2.pdf"
Public Shared ReadOnly SRC As String = "c:\temp1\1.pdf"
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim file As System.IO.FileInfo = New System.IO.FileInfo(DEST)
file.Directory.Create()
ManipulatePdf(DEST)
End Sub