ChangeTextAttrs.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 GrapeCity.Documents.Pdf
Imports GrapeCity.Documents.Pdf.TextMap
Imports GrapeCity.Documents.Pdf.Layers
Imports GrapeCity.Documents.Text

Public Class ChangeTextAttrs
    Public Function CreatePDF(ByVal stream As Stream) As Integer
        Dim doc = New GcPdfDocument()
        Using fs = File.OpenRead(Path.Combine("Resources", "PDFs", "TimeSheet.pdf"))
            doc.Load(fs)
            Dim pageCount = doc.Pages.Count
            ' Duplicate the PDF:
            doc.MergeWithDocument(doc)
            ' Modify text on the first copy:
            For i = 0 To pageCount - 1
                Dim ftps = New FindTextParams("\d+/\d+/\d+|\d+:\d+| am| pm", False, False, 72, 72, False, True)
                ' TextRenderingAttrs allows you to specify the following text rendering attributes:
                ' - RenderingMode
                ' - FillAlpha
                ' - FillColor
                ' - StrokeAlpha
                ' - StrokePen
                doc.Pages(i).SetTextRenderingAttrs(ftps, New TextRenderingAttrs() With {
                    .RenderingMode = TextRenderingMode.FillStroke,
                    .FillColor = Color.Red,
                    .FillAlpha = 0.5F,
                    .StrokeAlpha = 1.0F,
                    .StrokePen = New GrapeCity.Documents.Drawing.Pen(Color.Blue, 1)})
            Next
            '' Done:
            doc.Save(stream)
            Return doc.Pages.Count
        End Using
    End Function
End Class