RemoveSignatures.vb
  1. ''
  2. '' This code is part of Document Solutions for PDF demos.
  3. '' Copyright (c) MESCIUS inc. All rights reserved.
  4. ''
  5. Imports System.IO
  6. Imports GrapeCity.Documents.Pdf
  7. Imports GrapeCity.Documents.Pdf.AcroForms
  8.  
  9. '' This sample shows how to find and remove existing signatures
  10. '' from a PDF that had been digitally signed.
  11. '' See the RemoveSignatureFields for code that removes any
  12. '' signature fields instead.
  13. '' The PDF used in this sample was created by TimeSheet.
  14. Public Class RemoveSignatures
  15. Public Function CreatePDF(ByVal stream As Stream) As Integer
  16. Dim doc = New GcPdfDocument()
  17. Using fs As New FileStream(Path.Combine("Resources", "PDFs", "TimeSheet.pdf"), FileMode.Open, FileAccess.Read)
  18. doc.Load(fs)
  19.  
  20. '' Fields can be children of other fields, so we use
  21. '' a recursive method to iterate through the whole tree:
  22. RemoveSignatures(doc.AcroForm.Fields)
  23.  
  24. '' Done:
  25. doc.Save(stream)
  26. Return doc.Pages.Count
  27. End Using
  28. End Function
  29.  
  30. Sub RemoveSignatures(ByVal fields As FieldCollection)
  31. For i = fields.Count - 1 To 0 Step -1
  32. If TypeOf fields(i) Is SignatureField Then
  33. DirectCast(fields(i), SignatureField).Value = Nothing
  34. End If
  35. RemoveSignatures(fields(i).Children)
  36. Next
  37. End Sub
  38. End Class
  39.