VintaSoft Imaging .NET SDK 10.1
Vintasoft.Imaging.Text Namespace / TextRegion Class / GetLineSubregion Method / GetLineSubregion(PointF) Method
Location of line.
Example



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

    Parameters

    point
    Location of line.

    Return Value

    Text region that contains a line at specified point.
    Example
    This example shows how to get text line of PDF page.
    ''' <summary>
    ''' Returns the text line of PDF page.
    ''' </summary>
    ''' <param name="imageViewer">Image viewer.</param>
    ''' <param name="location">Point on image viewer.</param>
    ''' <returns>Text line of PDF page.</returns>
    Public Shared Function GetLineTextPage(imageViewer As Vintasoft.Imaging.UI.ImageViewer, location As System.Drawing.PointF) As String
        Dim image As Vintasoft.Imaging.VintasoftImage = imageViewer.Image
        If image.Metadata.TextRegion Is Nothing Then
            Return ""
        End If
                
        ' get transfrom from image to Text space 
        Dim fromImageToTextSpaceTransform As Vintasoft.Imaging.AffineMatrix = image.Metadata.TextRegion.GetTransformFromImageToTextSpace(image.Resolution)
                
        ' get transfrom from ImageViewer space to image space
        Dim fromImageViewerToImageSpaceTransform As Vintasoft.Imaging.AffineMatrix = imageViewer.GetTransformFromControlToImage(image)
                
        ' create transfrom from ImageViewer space to Text space
        Dim fromImageViewerToTextSpaceTransform As Vintasoft.Imaging.AffineMatrix = Vintasoft.Imaging.AffineMatrix.Multiply(fromImageViewerToImageSpaceTransform, fromImageToTextSpaceTransform)
                
        ' convert the point from the control coordinates to the text region coordinates
        location = Vintasoft.Imaging.PointFAffineTransform.TransformPoint(fromImageViewerToTextSpaceTransform, location)
                
        ' get the text line of the page
        Dim textRegion As Vintasoft.Imaging.Text.TextRegion = image.Metadata.TextRegion.GetLineSubregion(location)
                
        Dim textContent As String = String.Empty
        ' if text line is found
        If textRegion IsNot Nothing Then
            textContent = textRegion.TextContent
        End If
                
        Return textContent
    End Function
    /// <summary>
    /// Returns the text line of PDF page.
    /// </summary>
    /// <param name="imageViewer">Image viewer.</param>
    /// <param name="location">Point on image viewer.</param>
    /// <returns>Text line of PDF page.</returns>
    public static string GetLineTextPage(
        Vintasoft.Imaging.UI.ImageViewer imageViewer, 
        System.Drawing.PointF location)
    {
        Vintasoft.Imaging.VintasoftImage image = imageViewer.Image;
        if (image.Metadata.TextRegion == null)
            return "";
                
        // get transfrom from image to Text space 
        Vintasoft.Imaging.AffineMatrix fromImageToTextSpaceTransform = image.Metadata.TextRegion.GetTransformFromImageToTextSpace(image.Resolution);
                
        // get transfrom from ImageViewer space to image space
        Vintasoft.Imaging.AffineMatrix fromImageViewerToImageSpaceTransform = imageViewer.GetTransformFromControlToImage(image);
                
        // create transfrom from ImageViewer space to Text space
        Vintasoft.Imaging.AffineMatrix fromImageViewerToTextSpaceTransform = 
            Vintasoft.Imaging.AffineMatrix.Multiply(fromImageViewerToImageSpaceTransform, fromImageToTextSpaceTransform);
                
        // convert the point from the control coordinates to the text region coordinates
        location = Vintasoft.Imaging.PointFAffineTransform.TransformPoint(fromImageViewerToTextSpaceTransform, location);
                
        // get the text line of the page
        Vintasoft.Imaging.Text.TextRegion textRegion = 
            image.Metadata.TextRegion.GetLineSubregion(location);
                
        string textContent = string.Empty;
        // if text line is found
        if (textRegion != null)
            textContent = textRegion.TextContent;
                
        return textContent;
    }
    Requirements

    Target Platforms: .NET 6; .NET 5; .NET Core 3.1; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    See Also