VintaSoft Imaging .NET SDK 12.4: Documentation for .NET developer
Vintasoft.Imaging.Text Namespace / TextRegion Class / GetWordSubregion Methods / GetWordSubregion(PointF) Method
Syntax Example Requirements SeeAlso
In This Topic
    GetWordSubregion(PointF) Method (TextRegion)
    In This Topic
    Returns a text region that contains a word at specified point.
    Syntax
    'Declaration
    
    Public Overloads Function GetWordSubregion( _
    ByVal point
    Location of word.
    As System.Drawing.PointF _
    ) As TextRegion
    public TextRegion GetWordSubregion(
    System.Drawing.PointF point
    )
    public: TextRegion* GetWordSubregion(
    System.Drawing.PointF point
    )
    public:
    TextRegion^ GetWordSubregion(
    System.Drawing.PointF point
    )

    Parameters

    point
    Location of word.

    Return Value

    Text region that contains a word at specified point.
    Example

    This C#/VB.NET code shows how to get text word of PDF page.

    
    ''' <summary>
    ''' Returns word of PDF page.
    ''' </summary>
    ''' <param name="page">PDF page.</param>
    ''' <param name="imageViewer">Image viewer.</param>
    ''' <param name="location">Point on image viewer.</param>
    ''' <returns>Word of PDF page.</returns>
    Public Shared Function GetWordPage(page As Vintasoft.Imaging.Pdf.Tree.PdfPage, imageViewer As Vintasoft.Imaging.UI.ImageViewer, location As System.Drawing.Point) As String
        ' convert the point from the control coordinates to the image coordinates
        Dim imageCoordinateSystemPoint As System.Drawing.Point = imageViewer.PointToImage(location)
    
        Dim pdfPageCoordinateSystemPoint As System.Drawing.PointF = imageCoordinateSystemPoint
        ' get resolution of the image
        Dim resolution As Vintasoft.Imaging.Resolution = imageViewer.Image.Resolution
        ' convert point from the image coordinate space to the page coordinate space
        page.PointToUnit(pdfPageCoordinateSystemPoint, resolution)
    
        ' get word of the page
        Dim textRegion As Vintasoft.Imaging.Text.TextRegion = page.TextRegion.GetWordSubregion(pdfPageCoordinateSystemPoint)
    
        Dim textContent As String = String.Empty
        ' if word is searched
        If textRegion IsNot Nothing Then
            textContent = textRegion.TextContent
        End If
    
        Return textContent
    End Function
    
    
    
    /// <summary>
    /// Returns word of PDF page.
    /// </summary>
    /// <param name="page">PDF page.</param>
    /// <param name="imageViewer">Image viewer.</param>
    /// <param name="location">Point on image viewer.</param>
    /// <returns>Word of PDF page.</returns>
    public static string GetWordPage(
        Vintasoft.Imaging.Pdf.Tree.PdfPage page, 
        Vintasoft.Imaging.UI.ImageViewer imageViewer, 
        System.Drawing.Point location)
    {
        // convert the point from the control coordinates to the image coordinates
        System.Drawing.Point imageCoordinateSystemPoint = imageViewer.PointToImage(location);
    
        System.Drawing.PointF pdfPageCoordinateSystemPoint = imageCoordinateSystemPoint;
        // get resolution of the image
        Vintasoft.Imaging.Resolution resolution = imageViewer.Image.Resolution;
        // convert point from the image coordinate space to the page coordinate space
        page.PointToUnit(ref pdfPageCoordinateSystemPoint, resolution);
    
        // get word of the page
        Vintasoft.Imaging.Text.TextRegion textRegion = 
            page.TextRegion.GetWordSubregion(pdfPageCoordinateSystemPoint);
    
        string textContent = string.Empty;
        // if word is searched
        if (textRegion != null)
            textContent = textRegion.TextContent;
    
        return textContent;
    }
    
    

    Requirements

    Target Platforms: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    See Also