### Set OCR Language to Arabic Source: https://context7.com/iron-software/ironocr.examples/llms.txt Switch the recognition engine to Arabic by setting the Language property. Ensure the corresponding NuGet package is installed. ```csharp using IronOcr; var ocr = new IronTesseract(); oct.Language = OcrLanguage.Arabic; // Requires IronOcr.Languages.Arabic NuGet package using (var input = new OcrInput()) { input.AddImage("Inputs/arabic.gif"); OcrResult result = ocr.Read(input); Console.WriteLine(result.Text); // Output: Arabic text extracted from the image // Optionally save to a text file: // result.SaveAsTextFile("arabic.txt"); } ``` -------------------------------- ### Basic OCR from an Image File with IronTesseract Source: https://context7.com/iron-software/ironocr.examples/llms.txt Use the `IronTesseract.Read()` method with a file path for the simplest OCR operation. Ensure the image file exists at the specified path. ```csharp using IronOcr; var ocr = new IronTesseract(); // Pass a file path directly for the simplest case OcrResult result = ocr.Read(@"Inputs\Potter.tiff"); Console.WriteLine(result.Text); // Output: full extracted text from the image ``` -------------------------------- ### Reading with OcrInput for Multiple Sources Source: https://context7.com/iron-software/ironocr.examples/llms.txt Utilize `OcrInput` to load various document types like images, multi-frame TIFFs, and PDFs before OCR. This allows combining multiple sources into a single read operation. ```csharp using IronOcr; var ocr = new IronTesseract(); using (var input = new OcrInput()) { input.AddImage("Inputs/ComSci.png"); // Additional sources can be added: // input.AddPdf("Inputs/report.pdf"); // input.AddMultiFrameTiff("Inputs/multipage.tiff"); OcrResult result = ocr.Read(input); Console.WriteLine(result.Text); } ``` -------------------------------- ### Optimize Performance for Speed Source: https://context7.com/iron-software/ironocr.examples/llms.txt Tune performance by blacklisting characters, using Tesseract 5 with LSTM, and selecting a fast language model. This reduces processing time on clean inputs. ```csharp using IronOcr; var ocr = new IronTesseract(); // Speed-optimized configuration oct.Configuration.BlackListCharacters = "~`$#^*_}{][|\@"; // Skip rarely needed symbols oct.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.Auto; oct.Configuration.TesseractVersion = TesseractVersion.Tesseract5; oct.Configuration.EngineMode = TesseractEngineMode.LstmOnly; oct.Language = OcrLanguage.EnglishFast; // Lighter, faster language model using (var input = new OcrInput(@"Inputs\Potter.tiff")) { OcrResult result = ocr.Read(input); Console.WriteLine(result.Text); // Output: extracted text with significantly reduced processing time } ``` -------------------------------- ### Processing Low-Quality / Skewed Scans with Deskew Source: https://context7.com/iron-software/ironocr.examples/llms.txt Use `OcrInput.Deskew()` to automatically correct rotation and perspective distortion in scanned documents before OCR. This significantly improves accuracy on imperfect scans. ```csharp using IronOcr; var ocr = new IronTesseract(); using (var input = new OcrInput(@"Inputs\Potter.LowQuality.tiff")) { input.Deskew(); // Automatically corrects rotation and perspective OcrResult result = ocr.Read(input); Console.WriteLine(result.Text); // Output: corrected, accurate text despite the low-quality input } ``` -------------------------------- ### Combining Multiple Input Sources for Unified OCR Source: https://context7.com/iron-software/ironocr.examples/llms.txt Add multiple images and PDFs to a single `OcrInput` instance to process them together. The `OcrResult` will contain unified text spanning all processed sources. ```csharp using IronOcr; var ocr = new IronTesseract(); using (var input = new OcrInput()) { input.AddImage("Inputs/Potter.tiff"); input.AddPdf("Inputs/test.pdf"); OcrResult result = ocr.Read(input); Console.WriteLine($"Total pages processed: {result.Pages.Length}"); Console.WriteLine(result.Text); } ``` -------------------------------- ### Enable Barcode Reading Source: https://context7.com/iron-software/ironocr.examples/llms.txt Instruct the engine to detect and decode barcodes alongside text by setting `ReadBarCodes` to true. Decoded values are available in `OcrResult.Barcodes`. ```csharp using IronOcr; var ocr = new IronTesseract(); oct.Configuration.ReadBarCodes = true; // Enable barcode detection using (var input = new OcrInput()) { input.AddImage("Inputs/barcode.png"); OcrResult result = ocr.Read(input); Console.WriteLine("Text: " + result.Text); foreach (var barcode in result.Barcodes) { Console.WriteLine($"Barcode value: {barcode.Value}"); } } ``` -------------------------------- ### Reading Password-Protected PDFs Source: https://context7.com/iron-software/ironocr.examples/llms.txt Provide the password as the second argument to `OcrInput.AddPdf()` to unlock and extract text from encrypted PDF files. ```csharp using IronOcr; var ocr = new IronTesseract(); using (var input = new OcrInput()) { // Provide the PDF password as the second argument input.AddPdf("Inputs/test.pdf", "123"); OcrResult result = ocr.Read(input); Console.WriteLine(result.Text); // Output: text extracted from each page of the unlocked PDF } ``` -------------------------------- ### Recognize Multiple Simultaneous Languages Source: https://context7.com/iron-software/ironocr.examples/llms.txt Enable recognition of multiple languages within the same document by adding secondary languages. Custom Tesseract .traineddata files are also supported. ```csharp using IronOcr; var ocr = new IronTesseract(); oct.Language = OcrLanguage.Arabic; // Primary language oct.AddSecondaryLanguage(OcrLanguage.English); // Secondary language // ocr.AddSecondaryLanguage("custom.traineddata"); // Custom language data using (var input = new OcrInput()) { input.AddImage("Inputs/MultiLanguage.png"); OcrResult result = ocr.Read(input); Console.WriteLine(result.Text); // Output: mixed Arabic and English text recognized from the image } ``` -------------------------------- ### Cropping Region of Interest for Faster OCR Source: https://context7.com/iron-software/ironocr.examples/llms.txt Improve processing speed by specifying a `System.Drawing.Rectangle` to `OcrInput.AddImage()`, enabling OCR only on a particular pixel region. This is effective when relevant content is in a known area. ```csharp using IronOcr; using System.Drawing; var ocr = new IronTesseract(); using (var input = new OcrInput()) { // Define the pixel region containing the text of interest var contentArea = new Rectangle { X = 164, Y = 354, Width = 191, Height = 77 }; input.AddImage("Inputs/ComSci.png", contentArea); OcrResult result = ocr.Read(input); Console.WriteLine(result.Text); // Output: text extracted only from the specified rectangle } ``` -------------------------------- ### Export OCR Results as Searchable PDF Source: https://context7.com/iron-software/ironocr.examples/llms.txt Save OCR results to a PDF with a hidden text layer for searchability. A document title can be set on `OcrInput.Title`. ```csharp using IronOcr; var ocr = new IronTesseract(); using (var input = new OcrInput()) { input.Title = "Quarterly Report"; // Embedded document title input.AddImage("Inputs/Potter.tiff"); input.AddPdf("Inputs/test.pdf"); OcrResult result = ocr.Read(input); result.SaveAsSearchablePdf("Outputs/searchable.pdf"); // Output: a PDF at the specified path with selectable/searchable text } ``` -------------------------------- ### Export OCR Results as hOCR HTML Source: https://context7.com/iron-software/ironocr.examples/llms.txt Export OCR results to an hOCR-format HTML file, which includes word-level bounding boxes for downstream processing. ```csharp using IronOcr; var ocr = new IronTesseract(); using (var input = new OcrInput()) { input.Title = "Html Title"; // Title embedded in the hOCR output OcrResult result = ocr.Read("Inputs/Potter.tiff"); result.SaveAsHocrFile("Outputs/hocr.html"); // Output: standard hOCR HTML with word-level bounding boxes } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.