Skip to content
Guides

OCR

Overview

OCR (Optical Character Recognition) is the process of converting images of typed, handwritten, or printed text into machine-encoded text.

OCR is commonly used for text recognition and extraction from the following types of documents:

  • Non-editable scanned PDF files
  • Photographs of documents.
  • Scene photos such as advertising layouts, signboards, etc.
  • Identification cards, passports, vehicle license plates, and other official plates.
  • Invoices, bills, receipts, and other financial documents.

The following features support OCR:

  • PDF to Word
  • PDF to Excel
  • PDF to PPT
  • PDF to HTML
  • PDF to RTF
  • PDF to TXT
  • PDF to CSV
  • PDF to searchable PDF
  • Extract PDF to JSON
  • Extract PDF to Markdown

OCR Language Support of ComPDFKit Conversion SDK:

Script / NotesLanguage (Native)Language (In English)
Latn; AmericanEnglishEnglish
Latn; CanadianFrançais canadienFrench
Hans/Hant中文简体Chinese (Simplified)
Hans/Hant中文繁体Chinese (Traditional)
Jpan日本語Japanese
Kore한국어Korean
LatnDeutschGerman
LatnСрпски (латиница)Serbian (latin)
LatnOccitan, lenga d'òc, provençalOccitan
LatnDanskDanish
LatnItalianoItalian
Latn; EuropeanEspañolSpanish
Latn; EuropeanPortuguês (Portugal)Portuguese
LatnTe reo MāoriMaori
LatnBahasa MelayuMalay
LatnMaltiMaltese
LatnNederlandsDutch
Latn; BokmålNorskNorwegian
LatnPolskiPolish
LatnRomânăRomanian
LatnSlovenčinaSlovak
LatnSlovenščinaSlovenian
LatnshqipAlbanian
LatnSvenskaSwedish
LatnSwahiliSwahili
LatnWikang TagalogTagalog
LatnTürkçeTurkish
LatnoʻzbekchaUzbek
LatnTiếng ViệtVietnamese
LatnAfrikaansAfrikaans
LatnAzərbaycanAzerbaijani
LatnBosanskiBosnian
LatnČeštinaCzech
LatnCymraegWelsh
LatnEesti keelEstonian
LatnGaeilgeIrish
LatnHrvatskiCroatian
LatnMagyarHungarian
LatnBahasa IndonesiaIndonesian
LatnÍslenskaIcelandic
LatnKurdîKurdish
LatnLietuviųLithuanian
LatnLatviešuLatvian

Convert images to other document formats

The OCR function also supports converting input images into Word, Excel, PPT, HTML, CSV, RTF, TXT, Json and other formats. This sample demonstrates how to use the ComPDFKit OCR function to convert image files to DOCX file.

c#
// Set the OCR model path and language.
string modelPath = "***";
LibraryManager.SetDocumentAIModel(modelPath, OCRLanguage.e_English);

// Supports jpg, jpeg, png, bmp, tiff formats
string inputFilePath = "***";
string password = "***";
string outputFileName = "***";

WordOptions wordOptions = new WordOptions();
wordOptions.ContainImage = true;
wordOptions.ContainAnnotation = true;
wordOptions.EnableAiLayout = true;
// Enable OCR option.
wordOptions.EnableOCR = true;

ErrorCode error = CPDFConversion.StartPDFToWord(inputFilePath, password, outputFileName, wordOptions);

Notice

  • The quality of OCR results is related to the quality of the input image. If the input image resolution is lower, then the quality of the OCR results will also be affected. A good way is that the more pixels in the glyph, the better. If the glyph bounding box is smaller than 20x20 pixels, the OCR quality will begin to decline exponentially. The ideal image is a grayscale image with a resolution of around 300 DPI.
  • When performing OCR recognition, you need to pay attention to setting the OCR language and ensure that the selected OCR language is consistent with the language of the PDF document to obtain the best OCR conversion quality.
  • The OCR function currently does not support operating systems lower than Windows 10.

Integrate the Library of OCR

  1. Include the files "DocumentAI.dll", "fastdeploy.dll", "yaml-cpp.dll", "onnxruntime.dll", "onnxruntime_providers_shared.dll", and "paddle2onnx.dll" from the "x64" folder into your project, and set their Copy to Output Directory property to Copy if newer.

image-20250605160103868

  1. Set the option parameter options.EnableOCR to true.

Sample

This Sample demonstrates how to use the ComPDFKit OCR function to convert a PDF to DOCX file.

c#
string modelPath = "***";
LibraryManager.SetDocumentAIModel(modelPath, OCRLanguage.e_English);

string inputFilePath = "***";
string password = "***";
string outputFileName = "***";

WordOptions wordOptions = new WordOptions();
wordOptions.ContainImage = true;
wordOptions.ContainAnnotation = true;
wordOptions.EnableAiLayout = true;
// Enable OCR option.
wordOptions.EnableOCR = true;

ErrorCode error = CPDFConversion.StartPDFToWord(inputFilePath, password, outputFileName, wordOptions);