RemoveSignatureFields.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 signature fields from a PDF.
  10. '' The code in this sample is almost identical to the code in RemoveSignatures,
  11. '' which also finds all signature fields, but removes just the signatures,
  12. '' leaving the fields.
  13. '' The PDF used in this sample was created by TimeSheet.
  14. Public Class RemoveSignatureFields
  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. RemoveSignatureFields(doc.AcroForm.Fields)
  23.  
  24. '' Done:
  25. doc.Save(stream)
  26. Return doc.Pages.Count
  27. End Using
  28. End Function
  29.  
  30. Sub RemoveSignatureFields(ByVal fields As FieldCollection)
  31. For i = fields.Count - 1 To 0 Step -1
  32. RemoveSignatureFields(fields(i).Children)
  33. If TypeOf fields(i) Is SignatureField Then
  34. fields.RemoveAt(i)
  35. End If
  36. Next
  37. End Sub
  38. End Class
  39.