''
'' This code is part of Document Solutions for PDF demos.
'' Copyright (c) MESCIUS inc. All rights reserved.
''
Imports System.IO
Imports GrapeCity.Documents.Pdf
Imports GrapeCity.Documents.Pdf.AcroForms
'' This sample shows how to find and remove existing signatures
'' from a PDF that had been digitally signed.
'' See the RemoveSignatureFields for code that removes any
'' signature fields instead.
'' The PDF used in this sample was created by TimeSheet.
Public Class RemoveSignatures
Public Function CreatePDF(ByVal stream As Stream) As Integer
Dim doc = New GcPdfDocument()
Using fs As New FileStream(Path.Combine("Resources", "PDFs", "TimeSheet.pdf"), FileMode.Open, FileAccess.Read)
doc.Load(fs)
'' Fields can be children of other fields, so we use
'' a recursive method to iterate through the whole tree:
RemoveSignatures(doc.AcroForm.Fields)
'' Done:
doc.Save(stream)
Return doc.Pages.Count
End Using
End Function
Sub RemoveSignatures(ByVal fields As FieldCollection)
For i = fields.Count - 1 To 0 Step -1
If TypeOf fields(i) Is SignatureField Then
DirectCast(fields(i), SignatureField).Value = Nothing
End If
RemoveSignatures(fields(i).Children)
Next
End Sub
End Class