FlattenForm.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 System.Drawing
  7. Imports GrapeCity.Documents.Pdf
  8. Imports GrapeCity.Documents.Pdf.AcroForms
  9. Imports GrapeCity.Documents.Pdf.Graphics
  10. Imports GrapeCity.Documents.Drawing
  11. Imports GrapeCity.Documents.Text
  12.  
  13. '' This sample shows how to easily 'flatten' an AcroForm PDF with data -
  14. '' i.e. convert that form into a non-form PDF that looks Like the
  15. '' original filled form.
  16. '' The original filled form loaded by this sample Is generated by FormFields.
  17. Public Class FlattenForm
  18. Function CreatePDF(ByVal stream As Stream) As Integer
  19. Dim doc = New GcPdfDocument()
  20. Using fs = File.OpenRead(Path.Combine("Resources", "PDFs", "form-fields.pdf"))
  21. '' Load the filled PDF form into a temp document:
  22. Dim srcDoc = New GcPdfDocument()
  23. srcDoc.Load(fs)
  24. '' Draw all pages And annotation of the source PDF into the New one:
  25. For Each srcPage In srcDoc.Pages
  26. Dim page = doc.Pages.Add()
  27. Dim fxo = New FormXObject(doc, srcPage)
  28. page.Graphics.DrawForm(fxo, page.Bounds, Nothing, ImageAlign.Default)
  29. '' This method draws all annotations on the page including form field widgets:
  30. srcPage.DrawAnnotations(page.Graphics, page.Bounds)
  31. Next
  32. '' Done:
  33. doc.Save(stream)
  34. Return doc.Pages.Count
  35. End Using
  36. End Function
  37. End Class
  38.