OCRDocumentEx

OCR, rendering, document editing

Description

Runs OCRPageEx over a page range, retaining one raster page at a time

Syntax

Delphi

Function TPDFlib.OCRDocumentEx(Const PageRange: WideString; DPI: Double;
  Const Language, FontName: WideString; MinConfidence: Double;
  Options: Integer): Integer;

ActiveX

Function PDFlib::OCRDocumentEx(PageRange As String, DPI As Double, Language As String, FontName As String, MinConfidence As Double, Options As Long) As Long

DLL

int DLOCRDocumentEx(int InstanceID, const wchar_t* PageRange, double DPI, const wchar_t* Language, const wchar_t* FontName, double MinConfidence, int Options);
int DLOCRDocumentExA(int InstanceID, const char* PageRange, double DPI, const char* Language, const char* FontName, double MinConfidence, int Options);

Parameters

PageRangeA page-range expression such as 1-3,7, or an empty string for every page
DPIThe finite positive raster resolution
LanguageA provider-defined language hint
FontNameAn embeddable TrueType font or an empty string for fallback selection
MinConfidenceThe inclusive word-confidence threshold from 0 through 1
OptionsThe layer policy bits, with optional PDF_OCR_CONTINUE_ON_ERROR (4) and PDF_OCR_ATOMIC_DOCUMENT (8)

Return values

The number of pages processed before completion, failure or cancellation, including pages skipped by the existing-text policy and pages with no accepted words

A fully completed call returns the number of selected pages. The ordinary mode keeps the pages already processed. Atomic mode returns zero if any page fails or the operation is cancelled

Remarks

Each PNG is released before the next page is rendered, so peak raster memory follows the largest page rather than the page count

Use options 3 to retain native or foreign hidden text and refresh pages whose only text comes from owned OCR layers

Progress and cooperative cancellation use the normal operation lifecycle; provider cancellation leaves the current page's OCR result unapplied

GetOCRDiagnosticsJSON describes the last attempted or skipped page rather than an aggregate report for all pages

Batch reports and retry

PDF_OCR_CONTINUE_ON_ERROR records a page failure and keeps processing the remaining pages. Cancellation stops recognition and records the rest of the requested pages as not-run

PDF_OCR_ATOMIC_DOCUMENT stages changes on a private full-save snapshot. It adopts the OCR document only after every selected page is processed successfully. The document ID and selected page persist. Reacquire child object handles after a successful adoption. Combine both options to collect page failures before discarding the stage

Function TPDFlib.GetOCRDocumentReportJSON: WideString;
Function TPDFlib.GetOCRRetryPageRange: WideString;

The report lists every requested page and its individual completion, failure, cancellation or not-run status. Completed entries include the layer outcome and word count when available. The publication field identifies incremental application, adopted output, a discarded stage or an unchanged document. stagedPages counts pages that processed successfully before the publication decision

Call GetOCRRetryPageRange and pass the nonempty result back to OCRDocumentEx on the same document. Incremental mode lists failed, cancelled and unattempted pages. A discarded atomic stage lists all the selected pages. An empty retry range means no retry is pending

See also

OCRDocument, OCRPageEx, ConfigureTesseractOCR, GetOCRDiagnosticsJSON, LastOCRError