API referenceImages

pdfOCRImage

Run OCR (via the external OCR engine configured by

C
const char* __stdcall pdfOCRImageA(PPDF IPDF, const char* ImageFile, const char* Lang);
BOOL32 __stdcall pdfOCRImageToPDFA(PPDF IPDF, const char* ImageFile, const char* OutPdf, const char* Lang);
Delphi
function pdfOCRImageA(const IPDF: PPDF; const ImageFile, Lang: PAnsiChar): PAnsiChar; stdcall;
function pdfOCRImageToPDFA(const IPDF: PPDF; const ImageFile, OutPdf, Lang: PAnsiChar): LongBool; stdcall;

Purpose. Run OCR (via the external OCR engine configured by pdfSetOCREnginePath, HTML-with-Matrix Drawing, the GPC Polygon Clipper, and Remaining Utilities) on an image file: pdfOCRImage returns the recognized text; pdfOCRImageToPDF produces a searchable-image PDF (the source image with an invisible OCR text layer) written to OutPdf.

Description. pdfOCRImage calls OCRImageToText, returning the recognized text via a document-owned transient buffer (OCRTextPtr, overwritten on the next OCR call); pdfOCRImageToPDF calls the analogous OCRImageToPDF, which both runs OCR and produces the output file in one step. Both are real integrations with the external OCR engine (not stubs), but their success depends on that engine being correctly configured first via pdfSetOCREnginePath — this chapter does not independently re-verify the external-process invocation details or Lang code format expected by the configured engine.

Parameters.

ParameterDescription
IPDFDocument handle.
ImageFilePath to the source image to OCR.
OutPdf*(ToPDF only)* Output searchable-PDF path.
LangOCR language code, in whatever format the configured external OCR engine expects.

Return value. pdfOCRImage: recognized text, or nil on failure (engine not configured, image unreadable, OCR process failure). pdfOCRImageToPDF: True on success; False otherwise.

See also. pdfSetOCREnginePath.

C# (P/Invoke)

wrappers/dotnet/LumasPdf.cs
public static extern IntPtr pdfOCRImageA(IntPtr IPDF, [MarshalAs(UnmanagedType.LPStr)] string ImageFile, [MarshalAs(UnmanagedType.LPStr)] string Lang);
Area
Images
Category

Core

Exported names

pdfOCRImageA

String variants

The …A form takes UTF-8, …W takes UTF-16; a bare name aliases the ANSI form.

See working code

Worked examples — complete programs in ten languages.