VintaSoft Imaging .NET SDK v8.7
Vintasoft.Imaging.Pdf.Content.TextExtraction Namespace / PdfTextRegion Class / GetWordSubregion Method
Location of word.
Example



In This Topic
    GetWordSubregion Method (PdfTextRegion)
    In This Topic
    Returns a text region that contains a word at specified point.
    Syntax
    'Declaration
     
    Public Function GetWordSubregion( _
       ByVal point As PointF _
    ) As PdfTextRegion
    public PdfTextRegion GetWordSubregion( 
       PointF point
    )
    public: PdfTextRegion* GetWordSubregion( 
       PointF point
    ) 
    public:
    PdfTextRegion^ GetWordSubregion( 
       PointF point
    ) 

    Parameters

    point
    Location of word.

    Return Value

    Text region that contains a word at specified point.
    Example
    This example 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.Pdf.Content.TextExtraction.PdfTextRegion = 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.Pdf.Content.TextExtraction.PdfTextRegion textRegion = 
            page.TextRegion.GetWordSubregion(pdfPageCoordinateSystemPoint);
                
        string textContent = string.Empty;
        // if word is searched
        if (textRegion != null)
            textContent = textRegion.TextContent;
                
        return textContent;
    }
    Requirements

    Target Platforms: Windows 10, Windows 8, Windows 7, Windows Vista, Windows XP, Windows Server 2012, Windows Server 2008, Windows Server 2003

    See Also