VintaSoft Imaging .NET SDK 14.0: Документация для .NET разработчика
Vintasoft.Imaging.Text Namespace / TextRegion Class / GetWordSubregion Methods / GetWordSubregion(PointF) Method
Синтаксис Example Требования Смотрите также
В этом разделе
    GetWordSubregion(PointF) Метод (TextRegion)
    В этом разделе
    Возвращает текстовую область, содержащую слово в указанной точке.
    Синтаксис
    'Declaration
    
    Public Overloads Function GetWordSubregion( _
    ByVal point
    Местоположение слова.
    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
    Местоположение слова.

    Return Value

    Текстовая область, содержащая слово в указанной точке.
    Пример

    Вот C#/VB.NET код, который демонстрирует, как получить текстовое слово PDF страницы.

    
    ''' <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;
    }
    
    

    Требования

    Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    Смотрите также