VintaSoft Imaging .NET SDK 12.4: Documentation for .NET developer
Vintasoft.Imaging.Text Namespace / TextRegion Class / GetSubregion Methods / GetSubregion(RectangleF) Method
Syntax Example Requirements SeeAlso
In This Topic
    GetSubregion(RectangleF) Method (TextRegion)
    In This Topic
    Returns a subregion of this text region.
    Syntax
    'Declaration
    
    Public Overloads Function GetSubregion( _
    ByVal rect
    Location and size of subregion.
    As System.Drawing.RectangleF _
    ) As TextRegion
    public TextRegion GetSubregion(
    System.Drawing.RectangleF rect
    )

    Parameters

    rect
    Location and size of subregion.

    Return Value

    Subregion of this text region.
    Example

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

    
    ''' <summary>
    ''' Extracts text that is located in specified rectangle on PDF page.
    ''' </summary>
    ''' <param name="image">The image.</param>
    ''' <param name="rect">The rectange, in image space.</param>
    Public Shared Function ExtractText(image As Vintasoft.Imaging.VintasoftImage, rect As System.Drawing.RectangleF) As String
        ' get text region of image
        Dim textRegion As Vintasoft.Imaging.Text.TextRegion = image.Metadata.TextRegion
        If textRegion Is Nothing Then
            Return ""
        End If
    
        ' get transform from image to Text space
        Dim fromImageToTextSpaceTransform As Vintasoft.Imaging.AffineMatrix = image.Metadata.TextRegion.GetTransformFromImageToTextSpace(image.Resolution)
    
        ' transform rect to TextRegion space
        rect = Vintasoft.Imaging.Utils.GraphicsUtils.TransformRect(rect, fromImageToTextSpaceTransform)
    
        ' get text sub region for specified rect
        textRegion = textRegion.GetSubregion(rect, Vintasoft.Imaging.Text.TextSelectionMode.Rectangle)
    
        ' return text
        Return textRegion.TextContent
    End Function
    
    
    
    /// <summary>
    /// Extracts text that is located in specified rectangle on PDF page.
    /// </summary>
    /// <param name="image">The image.</param>
    /// <param name="rect">The rectange, in image space.</param>
    public static string ExtractText(
        Vintasoft.Imaging.VintasoftImage image,
        System.Drawing.RectangleF rect)
    {
        // get text region of image
        Vintasoft.Imaging.Text.TextRegion textRegion = image.Metadata.TextRegion;
        if (textRegion == null)
            return "";
    
        // get transform from image to Text space
        Vintasoft.Imaging.AffineMatrix fromImageToTextSpaceTransform = image.Metadata.TextRegion.GetTransformFromImageToTextSpace(image.Resolution);
    
        // transform rect to TextRegion space
        rect = Vintasoft.Imaging.Utils.GraphicsUtils.TransformRect(rect, fromImageToTextSpaceTransform);
    
        // get text sub region for specified rect
        textRegion = textRegion.GetSubregion(rect, Vintasoft.Imaging.Text.TextSelectionMode.Rectangle);
    
        // return text
        return textRegion.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