ReplaceText2.vb
''
'' This code is part of Document Solutions for PDF .NET demos.
'' Copyright (c) MESCIUS inc. All rights reserved.
''
Imports System.IO
Imports System.Drawing
Imports System.Text
Imports GrapeCity.Documents.Pdf
Imports GrapeCity.Documents.Text
Imports GrapeCity.Documents.Pdf.AcroForms

Public Class ReplaceText2
    Public Function CreatePDF(ByVal stream As Stream) As Integer
        Dim doc = New GcPdfDocument()
        Using fs = File.OpenRead(Path.Combine("Resources", "PDFs", "gc-docs-data-sheet.pdf"))
            doc.Load(fs)

            ' Replace:
            doc.ReplaceText(New FindTextParams(".NET Standard 2.0", False, True), ".NET 6")

            ' For reference, append the original PDF:
            Util.AddNote("For reference, the following pages contain a copy of the original unmodified PDF.", doc.NewPage())
            Dim docOrig = New GcPdfDocument()
            docOrig.Load(fs)
            doc.MergeWithDocument(docOrig)

            '' Done:
            doc.Save(stream)
            Return doc.Pages.Count
        End Using
    End Function
End Class