LoadPDF.vb
''
'' This code is part of GrapeCity Documents for PDF samples.
'' Copyright (c) GrapeCity, Inc. All rights reserved.
''
Imports System.IO
Imports System.Drawing
Imports System.Text
Imports GrapeCity.Documents.Pdf
Imports GrapeCity.Documents.Common
Imports GrapeCity.Documents.Drawing

'' This sample loads the PDF file created by the HelloWorld sample,
'' adds a short text note to the first page, and saves the result.
Public Class LoadPDF
    Function CreatePDF(ByVal stream As Stream) As Integer
        Dim doc = New GcPdfDocument()
        '' IMPORTANT: when working with an existing PDF file using GcPdfDocument.Load() method,
        '' the stream passed to that method MUST REMAIN OPEN while working with the document.
        '' This is because Load() does not load the whole PDF document into memory right away,
        '' instead it loads the various parts of the PDF as needed.
        '' The stream is only used for reading, and the original file itself is not modified.
        '' To save the changes you need to call one of the GcPdfDocument.Save() overloads
        '' as usual.
        Using fs = New FileStream(Path.Combine("Resources", "PDFs", "HelloWorld.pdf"), FileMode.Open, FileAccess.Read)
            doc.Load(fs)
            '' Add note to the (only) page in the doc:
            Dim page = doc.Pages.Last
            Util.AddNote(
                "This text was added to the original ""Hello World"" PDF.",
                page,
                New RectangleF(72, 72 * 3, page.Size.Width - 72 * 2, 72))
            ''
            '' Done:
            doc.Save(stream)
        End Using
        Return doc.Pages.Count
    End Function
End Class