LoadPDF.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 System.Text
  8. Imports GrapeCity.Documents.Pdf
  9. Imports GrapeCity.Documents.Common
  10. Imports GrapeCity.Documents.Drawing
  11.  
  12. '' This sample loads the PDF file created by the HelloWorld sample,
  13. '' adds a short text note to the first page, and saves the result.
  14. Public Class LoadPDF
  15. Function CreatePDF(ByVal stream As Stream) As Integer
  16. Dim doc = New GcPdfDocument()
  17. '' IMPORTANT: when working with an existing PDF file using GcPdfDocument.Load() method,
  18. '' the stream passed to that method MUST REMAIN OPEN while working with the document.
  19. '' This is because Load() does not load the whole PDF document into memory right away,
  20. '' instead it loads the various parts of the PDF as needed.
  21. '' The stream is only used for reading, and the original file itself is not modified.
  22. '' To save the changes you need to call one of the GcPdfDocument.Save() overloads
  23. '' as usual.
  24. Using fs = New FileStream(Path.Combine("Resources", "PDFs", "HelloWorld.pdf"), FileMode.Open, FileAccess.Read)
  25. doc.Load(fs)
  26. '' Add note to the (only) page in the doc:
  27. Dim page = doc.Pages.Last
  28. Util.AddNote(
  29. "This text was added to the original ""Hello World"" PDF.",
  30. page,
  31. New RectangleF(72, 72 * 3, page.Size.Width - 72 * 2, 72))
  32. ''
  33. '' Done:
  34. doc.Save(stream)
  35. End Using
  36. Return doc.Pages.Count
  37. End Function
  38. End Class
  39.