GetSubregion(RectangleF) Метод (TextRegion)
Возвращает субрегион этой текстовой области.
Parameters
- rect
- Расположение и размер субрегиона.
Return Value
Подрегион этой текстовой области.
Вот C#/VB.NET код, который демонстрирует, как получить текстовое содержимое области PDF страницы.
''' <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;
}
Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5