GemBox.Pdf
  • Overview
  • Examples
  • Free version
  • Support
  • Pricelist

    Show / Hide Table of Contents

    PdfText Class

    Namespace:
    GemBox.Pdf.Content
    Assembly:
    GemBox.Pdf.dll

    Represents a snapshot mapping from a sequence of Unicode characters to a sequence of complete, partial or none PdfContentElements and provides various text related functionalities.

    • C#
    • VB.NET
    public sealed class PdfText
    Public NotInheritable Class PdfText
    Inheritance:
    System.Object
    PdfText
    Remarks

    The PdfText is a snapshot and if the underlying PDF content is changed, that change won't be visible in the PdfText, instead PdfText should be retrieved again to get the actual snapshot.

    Properties

    Bounds

    Gets the bounds of the PdfText.

    • C#
    • VB.NET
    public PdfQuad Bounds { get; }
    Public ReadOnly Property Bounds As PdfQuad
    Property Value
    PdfQuad

    The bounds of the PdfText.

    Format

    Gets the formatting properties applied to the PdfText.

    • C#
    • VB.NET
    public PdfContentFormat Format { get; }
    Public ReadOnly Property Format As PdfContentFormat
    Property Value
    PdfContentFormat

    The formatting properties applied to the PdfText.

    Remarks

    Setting the properties of the returned PdfContentFormat is currently not supported.

    Length

    Gets the number of Unicode characters in the current PdfText object.

    • C#
    • VB.NET
    public int Length { get; }
    Public ReadOnly Property Length As Integer
    Property Value
    System.Int32

    The number of Unicode characters in the current PdfText object.

    Methods

    Find(String, StringComparison)

    Finds all occurrences of the specified text in this PdfText instance.

    • C#
    • VB.NET
    public IEnumerable<PdfText> Find(string text, StringComparison comparisonType = StringComparison.InvariantCulture)
    Public Function Find(text As String, comparisonType As StringComparison = StringComparison.InvariantCulture) As IEnumerable(Of PdfText)
    Parameters
    text
    System.String

    The searched text.

    comparisonType
    System.StringComparison

    One of the enumeration values that specifies the rules for the search.

    Returns
    System.Collections.Generic.IEnumerable<PdfText>

    All occurrences of the specified text in this PdfText instance.

    Exceptions
    System.ArgumentNullException

    text is null.

    Find(Regex)

    Finds all matches of the specified regular expression in this PdfText instance.

    • C#
    • VB.NET
    public IEnumerable<PdfText> Find(Regex regex)
    Public Function Find(regex As Regex) As IEnumerable(Of PdfText)
    Parameters
    regex
    System.Text.RegularExpressions.Regex

    The regular expression used to find the matches.

    Returns
    System.Collections.Generic.IEnumerable<PdfText>

    All matches of the specified regular expression in this PdfText instance.

    Exceptions
    System.ArgumentNullException

    regex is null.

    Highlight()

    Highlights the PDF content associated with the current PdfText.

    • C#
    • VB.NET
    public PdfContentFormat Highlight()
    Public Function Highlight As PdfContentFormat
    Returns
    PdfContentFormat

    The PdfContentFormat used to customize the highlight.

    Redact()

    Removes the PDF content associated with the current PdfText.

    • C#
    • VB.NET
    public void Redact()
    Public Sub Redact

    Replace(PdfFormattedText)

    Replaces the current PdfText with the specified PdfFormattedText at the position of the first glyph.

    • C#
    • VB.NET
    public void Replace(PdfFormattedText formattedText)
    Public Sub Replace(formattedText As PdfFormattedText)
    Parameters
    formattedText
    PdfFormattedText

    The PdfFormattedText to replace the current PdfText.

    Remarks

    To ensure visual consistency, the provided PdfFormattedText should match the formatting of the current text.

    This can be achieved by setting Font to Format.Text.Font and Color to Format.Fill.Color.

    Replace(String)

    Replaces the current PdfText with the specified plain text at the position of the first glyph.

    • C#
    • VB.NET
    public void Replace(string text)
    Public Sub Replace(text As String)
    Parameters
    text
    System.String

    The text to replace the current PdfText.

    Subtext(Int32)

    Retrieves a subtext from this instance. The subtext starts at a specified character position and continues to the end of the text.

    • C#
    • VB.NET
    public PdfText Subtext(int startIndex)
    Public Function Subtext(startIndex As Integer) As PdfText
    Parameters
    startIndex
    System.Int32

    The zero-based starting character position of a subtext in this instance.

    Returns
    PdfText

    A PdfText that is equivalent to the subtext that begins at startIndex in this instance.

    Exceptions
    System.ArgumentOutOfRangeException

    startIndex is less than zero or greater than the length of this instance.

    Subtext(Int32, Int32)

    Retrieves a subtext from this instance. The subtext starts at a specified character position and has a specified length.

    • C#
    • VB.NET
    public PdfText Subtext(int startIndex, int length)
    Public Function Subtext(startIndex As Integer, length As Integer) As PdfText
    Parameters
    startIndex
    System.Int32

    The zero-based starting character position of a subtext in this instance.

    length
    System.Int32

    The number of characters in the subtext.

    Returns
    PdfText

    A PdfText that is equivalent to the subtext of length length that begins at startIndex in this instance.

    Exceptions
    System.ArgumentOutOfRangeException

    startIndex plus length indicates a position not within this instance or startIndex or length is less than zero.

    ToString()

    Returns a Unicode text contained in this PdfText.

    • C#
    • VB.NET
    public override string ToString()
    Public Overrides Function ToString As String
    Returns
    System.String

    A Unicode text contained in this PdfText.

    Overrides
    System.Object.ToString()

    See Also

    PDF Specification ISO 32000-1:2008, section '9.10 Extraction of Text Content'
    PDF Specification ISO 32000-1:2008, section '14.9.4 Replacement Text'
    Back to top

    Facebook • Twitter • LinkedIn

    © GemBox Ltd. — All rights reserved.