''' <summary>
''' Highlights specified text in PDF document.
''' </summary>
''' <param name="inputPdfFilename">The input PDF filename.</param>
''' <param name="outputPdfFilename">The output PDF filename.</param>
''' <param name="text">A text that must be highlighted.</param>
Public Shared Sub HiglightTextInPdfDocument(inputPdfFilename As String, outputPdfFilename As String, text As String)
MarkupTextInPdfDocument(inputPdfFilename, outputPdfFilename, Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationType.Highlight, System.Drawing.Color.Orange, text)
End Sub
''' <summary>
''' Strikeouts specified text in PDF document.
''' </summary>
''' <param name="inputPdfFilename">The input PDF filename.</param>
''' <param name="outputPdfFilename">The output PDF filename.</param>
''' <param name="text">A text that must be striked out.</param>
Public Shared Sub StrikeoutTextInPdfDocument(inputPdfFilename As String, outputPdfFilename As String, text As String)
MarkupTextInPdfDocument(inputPdfFilename, outputPdfFilename, Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationType.StrikeOut, System.Drawing.Color.Red, text)
End Sub
''' <summary>
''' Underlines specified text in PDF document.
''' </summary>
''' <param name="inputPdfFilename">The input PDF filename.</param>
''' <param name="outputPdfFilename">The output PDF filename.</param>
''' <param name="text">A text that must be underlined.</param>
Public Shared Sub UnderlineTextInPdfDocument(inputPdfFilename As String, outputPdfFilename As String, text As String)
MarkupTextInPdfDocument(inputPdfFilename, outputPdfFilename, Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationType.Underline, System.Drawing.Color.Green, text)
End Sub
''' <summary>
''' Squiggly undeline specified text in PDF document.
''' </summary>
''' <param name="inputPdfFilename">The input PDF filename.</param>
''' <param name="outputPdfFilename">The output PDF filename.</param>
''' <param name="text">A text that must be squiggly underlined.</param>
Public Shared Sub SquigglyUnderlineTextInPdfDocument(inputPdfFilename As String, outputPdfFilename As String, text As String)
MarkupTextInPdfDocument(inputPdfFilename, outputPdfFilename, Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationType.Squiggly, System.Drawing.Color.Blue, text)
End Sub
''' <summary>
''' Markups specified text in PDF document.
''' </summary>
''' <param name="inputPdfFilename">The input PDF filename.</param>
''' <param name="outputPdfFilename">The output PDF filename.</param>
''' <param name="color">The markup annotation color.</param>
''' <param name="annotationType">The markup annotation type.</param>
''' <param name="text">A text to markup.</param>
Private Shared Sub MarkupTextInPdfDocument(inputPdfFilename As String, outputPdfFilename As String, annotationType As Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationType, color As System.Drawing.Color, text As String)
' open input PDF document
Using document As New Vintasoft.Imaging.Pdf.PdfDocument(inputPdfFilename)
' for each PDF page
For Each page As Vintasoft.Imaging.Pdf.Tree.PdfPage In document.Pages
' extract text region of PDF page
Dim pageTextRegion As Vintasoft.Imaging.Text.TextRegion = page.ExtractTextRegion(False)
' search and markup all specified text on PDF page
Dim index As Integer = 0
Dim foundText As Vintasoft.Imaging.Text.TextRegion
While True
' find next text
foundText = pageTextRegion.FindText(text, index, False)
If foundText Is Nothing Then
Exit While
End If
index += foundText.Symbols.Length
' markup found text
MarkupText(page, foundText, annotationType, color)
End While
Next
' save PDF document to output file
document.SaveChanges(outputPdfFilename)
End Using
End Sub
''' <summary>
''' Markups specified text region in PDF page.
''' </summary>
''' <param name="page">The page.</param>
''' <param name="textRegion">The text region to markup.</param>
''' <param name="color">The markup annotation color.</param>
''' <param name="annotationType">The markup annotation type.</param>
Private Shared Sub MarkupText(page As Vintasoft.Imaging.Pdf.Tree.PdfPage, textRegion As Vintasoft.Imaging.Text.TextRegion, annotationType As Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationType, color As System.Drawing.Color)
' create markup annotation of specified type
Dim markupAnnotation As New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfTextMarkupAnnotation(page, annotationType)
' set annotation properties
markupAnnotation.SetArea(textRegion)
markupAnnotation.Color = color
markupAnnotation.Title = System.Environment.UserName
markupAnnotation.CreationDate = System.DateTime.Now
' generate annotation appearance
markupAnnotation.UpdateAppearance()
' add annotation to annotations of PDF page
If page.Annotations Is Nothing Then
page.Annotations = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(page.Document)
End If
page.Annotations.Add(markupAnnotation)
End Sub