Tutorials > Perform OCR |
![]() |
Before using OCR features, you should setup OCR modules first. For more information, see OCR Module Installation. |
The following code performs OCR on a document at once using Document.PerformOCR Method. This is the easiest way to perform OCR.
djvuocr.cs |
Copy Code |
---|---|
using System; using DjVu; namespace DjVuOcr { class DjVuOcr { static void Main(string[] args) { // TODO: ADD app's license script here or REMOVE the following line LicenseManager.LicenseScript = "......"; using (Document doc = new Document(args[0])) { doc.PerformOCR(false); doc.SaveAs(args[1]); } } } } |
Of course, you can perform OCR on page by page basis. This is better if you want to interact with user because you can add some GUI/CUI codes around the OCR call.
djvuocrpxp.cs |
Copy Code |
---|---|
using System; using DjVu; namespace SavePageByPage { class SavePageByPage { static void Main(string[] args) { // TODO: ADD app's license script here or REMOVE the following line LicenseManager.LicenseScript = "......"; using (Document doc = new Document(args[0])) { for (int i = 0; i < doc.Pages.Count; i++) { Console.WriteLine("OCR {0}/{1}...", i + 1, doc.Pages.Count); doc.Pages[i].PerformOCR(false); } doc.SaveAs(args[1]); } } } } |
Basically, OCR parameters are initialized automatically based on the thread locale. On typical situation, if the machine is running Japanese Windows XP, the OCR is configured for Japanese by default. You can override the default settings by explicitly passing OcrSettings Class object to OCR methods.
Some PerformOCR methods do not accept OcrSettings object and they use the global settings. The global OCR parameters can be configured using GlobalOcrSettings Class.
djvuocrja.cs |
Copy Code |
---|---|
using System; using DjVu; namespace DjVuOcr { class DjVuOcr { static void Main(string[] args) { // TODO: ADD app's license script here or REMOVE the following line LicenseManager.LicenseScript = "......"; using (Document doc = new Document(args[0])) { // Explicitly configure OCR for Japanese Ocr.OcrSettings os = new Ocr.OcrSettings(Ocr.Language.Japanese); doc.PerformOCR(os, false); doc.SaveAs(args[1]); } } } } |