ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Core.OCR Namespace / OCRManager Class / ExtractTextFromDocumentAsync Method / ExtractTextFromDocumentAsync(String,Int32,CancellationToken) Method
The document image. See IsValidDocumentForOCR for information about the file extensions supported.
The page you wish to extract information from. The index is 0-based; meaning that you should pass 0 for the first page; 1 for the second page and so on. Use -1 to extract data from all pages in the document image.
A System.Threading.CancellationToken used to control cancellation behavior for the returned task.

In This Topic
    ExtractTextFromDocumentAsync(String,Int32,CancellationToken) Method
    In This Topic
    Extracts text from a specific page of a document image using the OCROutputType.Text output type. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Overloads Function ExtractTextFromDocumentAsync( _
       ByVal documentFileName As String, _
       ByVal page As Integer, _
       ByVal cancellationToken As CancellationToken _
    ) As Task(Of String)

    Parameters

    documentFileName
    The document image. See IsValidDocumentForOCR for information about the file extensions supported.
    page
    The page you wish to extract information from. The index is 0-based; meaning that you should pass 0 for the first page; 1 for the second page and so on. Use -1 to extract data from all pages in the document image.
    cancellationToken
    A System.Threading.CancellationToken used to control cancellation behavior for the returned task.

    Return Value

    A string containing the text extracted. The string can be empty if no data can be extracted.
    Exceptions
    ExceptionDescription
    documentFileName is null.
    The document image could not be found or has an invalid extension for OCR.
    An error occurred within the OCR engine.
    The operation was canceled.
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Remarks
    Optical Character Recognition (OCR) technology is used to extract text from the document image. Text extraction and character recognition will be dependent on the quality and content of the image. There might also be difficulty in extracting text from complex data.

    Use this method to obtain information from a specific page in the document. Use GetDocumentPageCount to obtain the number of pages in the document image. If you specify a page that is greater than the page count, then null will be returned. Alternatively you can use ExtractTextFromDocumentAsync(String,CancellationToken) to obtain information from the entire document.

    If you wish to specify a specific output type or customize other options, use the ExtractFromDocumentAsync(OCROptions) or ExtractFromDocumentAsync(OCROptions,CancellationToken) overloads and set the options such as OCROptions.OutputType as appropriate.

    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.8 or higher.
    See Also