### Project Overview and Quick Start Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/START-HERE.md This snippet indicates where to find the project overview, features, and quick start guide. It's a starting point for understanding the library's capabilities and supported platforms. ```markdown Read: README.md → Quick Start section Time: 5 minutes Outcome: Understand what Spire.OCR does and supported platforms ``` -------------------------------- ### Complete Configuration Example Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/ConfigureOptions.md Demonstrates a complete configuration of the OcrScanner using the ConfigureOptions class. ```APIDOC ## Complete Configuration Example ### Description This example shows how to create and configure the `OcrScanner` with `ConfigureOptions`. ### Code ```csharp // Create and configure the scanner OcrScanner scanner = new OcrScanner(); ConfigureOptions options = new ConfigureOptions(); options.ModelPath = "D:\\win-x64"; // Required: path to model files options.Language = "English"; // Default language options.AutoRotate = true; // Enable rotation detection scanner.ConfigureDependencies(options); // Now scanner is ready to use scanner.Scan("document.png"); string result = scanner.Text.ToString(); ``` ``` -------------------------------- ### Install Spire.OCR Package Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/README.md Install the Spire.OCR NuGet package using the Package Manager Console. ```bash Install-Package Spire.OCR ``` -------------------------------- ### Complete OCR Example with Visual Text Alignment Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/VisualTextAligner.md This example demonstrates a full OCR process, including scanner configuration, image scanning, and obtaining visually aligned text using VisualTextAligner. It shows how to set up options like AutoRotate and save the results to a file. ```csharp using Spire.OCR; using System; using System.IO; public class Program { public static void Main() { // Initialize scanner OcrScanner scanner = new OcrScanner(); // Configure options ConfigureOptions options = new ConfigureOptions(); options.ModelPath = "D:\\win-x64"; options.Language = "English"; options.AutoRotate = true; // Handle rotated images scanner.ConfigureDependencies(options); try { // Scan image string imagePath = "document.png"; scanner.Scan(imagePath); // Get visually aligned text VisualTextAligner aligner = new VisualTextAligner(scanner.Text); string result = aligner.ToString(); // Save result string outputPath = "output.txt"; File.WriteAllText(outputPath, result); Console.WriteLine($"OCR completed. Results saved to {outputPath}"); } finally { scanner.Dispose(); } } } ``` -------------------------------- ### Handling Rotated Images Example Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/START-HERE.md This snippet points to an example demonstrating how to handle rotated images. It references the AutoRotate configuration option and provides a practical code example. ```markdown Example: [Complete-Example.md#handling-rotated-images](api-reference/Complete-Example.md#handling-rotated-images) ``` -------------------------------- ### C# Performance Patterns Example Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/MANIFEST.md Showcases techniques and patterns for optimizing OCR performance. ```csharp // Placeholder for C# performance patterns code ``` -------------------------------- ### C# Basic Image Scanning Example Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/START-HERE.md This snippet points to a C# example demonstrating basic image scanning. It's intended for C# developers who want to learn how to extract text from an image using Spire.OCR. ```markdown Read: api-reference/Complete-Example.md → Basic Image Scanning Time: 10 minutes Outcome: Know how to scan an image and extract text ``` -------------------------------- ### VB.NET Multi-Language Support Example Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/MANIFEST.md Demonstrates configuring and performing OCR for multiple languages in VB.NET. ```vbnet ' Placeholder for VB.NET multi-language support code ``` -------------------------------- ### C# Multi-Language OCR Example Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/MANIFEST.md Demonstrates configuring and performing OCR for multiple languages. ```csharp // Placeholder for C# multi-language OCR code ``` -------------------------------- ### VB.NET Text Block Navigation Example Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/MANIFEST.md Shows how to navigate and extract information from text blocks in VB.NET. ```vbnet ' Placeholder for VB.NET text block navigation code ``` -------------------------------- ### VB.NET Basic Scanning Example Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/START-HERE.md This snippet directs VB.NET developers to an example for basic image scanning. It helps them understand how to use Spire.OCR for text extraction in their VB.NET projects. ```markdown Read: api-reference/VB.NET-Examples.md → Basic Scanning Time: 10 minutes Outcome: Know how to scan an image and extract text ``` -------------------------------- ### Batch Processing Multiple Images Example Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/START-HERE.md This snippet directs users to an example showcasing how to process multiple images in a batch. It's relevant for applications that need to handle a large number of images efficiently. ```markdown See: [Complete-Example.md#batch-processing-multiple-images](api-reference/Complete-Example.md#batch-processing-multiple-images) ``` -------------------------------- ### VB.NET Basic Scanning Example Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/MANIFEST.md Demonstrates the fundamental process of scanning a local image file using Spire.OCR for .NET in VB.NET. ```vbnet ' Placeholder for VB.NET basic scanning code ``` -------------------------------- ### C# Basic Image Scanning Example Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/MANIFEST.md Demonstrates the fundamental process of scanning a local image file using Spire.OCR for .NET. ```csharp // Placeholder for C# basic image scanning code ``` -------------------------------- ### C# Text Block Navigation Example Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/MANIFEST.md Shows how to navigate and extract information from the hierarchical text blocks recognized in an image. ```csharp // Placeholder for C# text block navigation code ``` -------------------------------- ### Basic Configuration Guide Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/START-HERE.md This snippet directs users to the configuration documentation, focusing on essential settings like ModelPath and Language. It's crucial for setting up the OCR library correctly. ```markdown Read: configuration.md → ModelPath and Language sections Time: 10 minutes Outcome: Understand how to configure the library ``` -------------------------------- ### VB.NET Stream Processing Example Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/MANIFEST.md Illustrates how to perform OCR on image data provided as a stream in VB.NET. ```vbnet ' Placeholder for VB.NET stream processing code ``` -------------------------------- ### Extracting Text with Bounding Boxes Example Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/START-HERE.md This snippet highlights an example for extracting text along with its bounding box coordinates. It's useful for scenarios where precise text location is required. ```markdown Example: [Complete-Example.md#extract-text-with-bounding-boxes](api-reference/Complete-Example.md#extract-text-with-bounding-boxes) ``` -------------------------------- ### C# Advanced Patterns Example Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/MANIFEST.md Covers more complex usage scenarios and advanced features of Spire.OCR for .NET. ```csharp // Placeholder for C# advanced patterns code ``` -------------------------------- ### Batch Process Documents by Language Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/VB.NET-Examples.md Process multiple documents for different languages in batches. This example organizes documents by language and saves the extracted text to categorized output files. ```vbnet Imports Spire.OCR Imports System Imports System.Collections.Generic Imports System.IO Public Class LanguageBatchExample Public Shared Sub ProcessDocuments(documentsByLanguage As Dictionary(Of String, List(Of String))) Dim scanner As New OcrScanner() Dim options As New ConfigureOptions() options.ModelPath = "D:\win-x64" scanner.ConfigureDependencies(options) For Each languagePair In documentsByLanguage Dim language As String = languagePair.Key Dim documents As List(Of String) = languagePair.Value options.Language = language scanner.ConfigureDependencies(options) For Each docPath In documents scanner.Scan(docPath) Dim result As String = scanner.Text.ToString() Dim outputPath As String = Path.Combine( "output", language, Path.GetFileNameWithoutExtension(docPath) & ".txt" ) Directory.CreateDirectory(Path.GetDirectoryName(outputPath)) File.WriteAllText(outputPath, result) Next Next scanner.Dispose() End Sub Public Shared Sub Main() Dim docs As New Dictionary(Of String, List(Of String)) From { {"English", New List(Of String) From {"english1.jpg", "english2.jpg"}}, {"Japan", New List(Of String) From {"japanese1.jpg", "japanese2.jpg"}}, {"Chinese", New List(Of String) From {"chinese1.jpg", "chinese2.jpg"}} } ProcessDocuments(docs) End Sub End Class ``` -------------------------------- ### C# Stream-Based Processing Example Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/MANIFEST.md Illustrates how to perform OCR on image data provided as a stream, supporting various image formats. ```csharp // Placeholder for C# stream-based processing code ``` -------------------------------- ### VB.NET Error Handling Example Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/MANIFEST.md Provides patterns for robust error handling when using Spire.OCR in VB.NET. ```vbnet ' Placeholder for VB.NET error handling code ``` -------------------------------- ### Configuration Validation for VB.NET OCR Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/VB.NET-Examples.md This example demonstrates how to validate OCR configuration options, including checking if the model path exists and if the specified language is supported. It's crucial to validate configurations before initializing the scanner. ```vbnet Imports Spire.OCR Imports System Imports System.IO Public Class ValidationExample Public Shared Function ValidateConfiguration(options As ConfigureOptions) As Boolean ' Validate ModelPath If String.IsNullOrWhiteSpace(options.ModelPath) Then Console.WriteLine("Error: ModelPath is required") Return False End If If Not Directory.Exists(options.ModelPath) Then Console.WriteLine($"Error: ModelPath does not exist: {options.ModelPath}") Return False End If ' Validate Language Dim validLanguages As String() = { "English", "Chinese", "Chinesetraditional", "French", "German", "Japan", "Korean" } If Not Array.Exists(validLanguages, Function(l) l = options.Language) Then Console.WriteLine($"Error: Unsupported language: {options.Language}") Return False End If Return True End Function Public Shared Sub Main() Dim options As New ConfigureOptions() options.ModelPath = "D:\win-x64" options.Language = "English" If Not ValidateConfiguration(options) Then Return ' Stop execution End If Dim scanner As New OcrScanner() scanner.ConfigureDependencies(options) ' Continue with scanning... scanner.Dispose() End Sub End Class ``` -------------------------------- ### C# Error Handling Example Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/MANIFEST.md Provides patterns for robust error handling when using the Spire.OCR library. ```csharp // Placeholder for C# error handling code ``` -------------------------------- ### Create ConfigureOptions with Defaults Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/ConfigureOptions.md Instantiates the ConfigureOptions class using its default constructor. This is useful for starting with a base configuration before applying specific settings. ```csharp ConfigureOptions options = new ConfigureOptions(); ``` -------------------------------- ### Extract Text from Image Stream Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/VB-Examples/ocr_vb.md This example shows how to extract text from an image provided as a stream. It requires setting up the scanner configuration and then scanning the stream with the appropriate image format. ```vbnet ' Create an instance of the OcrScanner class Dim scanner As New OcrScanner() ' Create an instance of the ConfigureOptions class to set up the scanner configuration Dim configureOptions As New ConfigureOptions() ' Set the path to the new model (Must be modified to your actual model path) configureOptions.ModelPath = "D:\win-x64" ' Set the language for text recognition. The default is English. ' Supported languages include English, Chinese, Chinesetraditional, French, German, Japan, and Korean. configureOptions.Language = "English" ' Apply the configuration options to the scanner scanner.ConfigureDependencies(configureOptions) ' Get image stream Dim stream As Stream = (New StreamReader(imageFile)).BaseStream ' Scan image stream scanner.Scan(stream, OCRImageFormat.Jpg) ' Get the recognized text Dim recognizedText As String = scanner.Text.ToString() ' Clean up resources stream.Close() scanner.Dispose() ``` -------------------------------- ### C# Handling Rotated Images Example Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/MANIFEST.md Illustrates how Spire.OCR for .NET handles and corrects rotated images during the OCR process. ```csharp // Placeholder for C# handling rotated images code ``` -------------------------------- ### Full Namespace Usage Example Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/Spire.OCR-namespace.md This snippet demonstrates the complete workflow for using the Spire.OCR namespace, from initialization and configuration to scanning an image, processing results, and saving formatted output. Ensure OCR model files are correctly placed and referenced. ```csharp using Spire.OCR; using System; using System.IO; public class Program { public static void Main() { // Initialize scanner OcrScanner scanner = new OcrScanner(); // Configure options ConfigureOptions options = new ConfigureOptions(); options.ModelPath = "D:\\win-x64"; options.Language = "English"; options.AutoRotate = true; scanner.ConfigureDependencies(options); try { // Scan image scanner.Scan("document.png"); // Process results IOCRResult result = scanner.Text; // Extract all text string allText = result.ToString(); // Or process blocks foreach (IOCRTextBlock block in result.Blocks) { Console.WriteLine($"{block.Level}: {block.Text}"); Console.WriteLine($"Box: {block.Box}"); } // Use text aligner for formatted output VisualTextAligner aligner = new VisualTextAligner(result); string formatted = aligner.ToString(); // Save results File.WriteAllText("output.txt", formatted); } finally { scanner.Dispose(); } } } ``` -------------------------------- ### VB.NET Rotated Images Example Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/MANIFEST.md Illustrates how Spire.OCR for .NET handles and corrects rotated images in VB.NET. ```vbnet ' Placeholder for VB.NET rotated images code ``` -------------------------------- ### Cross-Platform Model Path Configuration Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/configuration.md Sets the model path dynamically based on the operating system to ensure cross-platform compatibility. This example checks for Windows, Linux, and macOS. ```csharp OcrScanner scanner = new OcrScanner(); ConfigureOptions options = new ConfigureOptions(); // Cross-platform model path string modelDirectory = "models"; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { modelDirectory = Path.Combine("C:", "ProgramFiles", "SpireOCR"); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { modelDirectory = "/opt/ocr/models"; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { modelDirectory = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Library", "Application Support", "SpireOCR" ); } options.ModelPath = modelDirectory; options.Language = "English"; scanner.ConfigureDependencies(options); ``` -------------------------------- ### Complete OCR Scanner Configuration Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/ConfigureOptions.md Demonstrates a full configuration of the OcrScanner using the ConfigureOptions class. This includes setting the required ModelPath, Language, and enabling AutoRotate for comprehensive OCR setup. ```csharp // Create and configure the scanner OcrScanner scanner = new OcrScanner(); ConfigureOptions options = new ConfigureOptions(); options.ModelPath = "D:\\win-x64"; // Required: path to model files options.Language = "English"; // Default language options.AutoRotate = true; // Enable rotation detection scanner.ConfigureDependencies(options); // Now scanner is ready to use scanner.Scan("document.png"); string result = scanner.Text.ToString(); ``` -------------------------------- ### Basic OCR Text Extraction Implementation Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/VB-Examples/ocr_vb.md This is a fundamental example for extracting text from an image file using Spire.OCR. It initializes the scanner, sets the model path and language, performs the scan, and retrieves the extracted text. ```vbnet ' Create an instance of the OcrScanner class Dim scanner As New OcrScanner() ' Create an instance of the ConfigureOptions class to set up the scanner configuration Dim configureOptions As New ConfigureOptions() ' Set the path to the new model (Must be modified to your actual model path) configureOptions.ModelPath = "D:\win-x64" ' Set the language for text recognition. The default is English. ' Supported languages include English, Chinese, Chinesetraditional, French, German, Japan, and Korean. configureOptions.Language = "English" ' Apply the configuration options to the scanner scanner.ConfigureDependencies(configureOptions) ' Scan image file scanner.Scan(imageFile) ' Get the extracted text Dim extractedText As String = scanner.Text.ToString() scanner.Dispose() ``` -------------------------------- ### Scan Image and Get Text (VB.NET) Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/VB.NET-Examples.md Scans a JPG image file and extracts its text content. Ensure the model path is correctly configured. ```vbnet Imports Spire.OCR Imports System Imports System.IO Public Class BasicExample Public Shared Sub Main() Dim scanner As New OcrScanner() ' Configure Dim options As New ConfigureOptions() options.ModelPath = "D:\win-x64" options.Language = "English" scanner.ConfigureDependencies(options) ' Scan and extract scanner.Scan("document.jpg") Dim result As String = scanner.Text.ToString() Console.WriteLine(result) scanner.Dispose() End Sub End Class ``` -------------------------------- ### Retrieving Bounding Box and Dimensions from IOCRTextBlock Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/IOCRTextBlock.md Shows how to get the bounding rectangle for each text block, including its position (X, Y) and size (Width, Height) in pixels. This is useful for image manipulation or highlighting detected text areas. ```csharp OcrScanner scanner = new OcrScanner(); ConfigureOptions options = new ConfigureOptions(); options.ModelPath = "D:\\win-x64"; options.Language = "English"; scanner.ConfigureDependencies(options); scanner.Scan("document.png"); IOCRTextBlock[] blocks = scanner.Text.Blocks; foreach (IOCRTextBlock block in blocks) { Rectangle rect = block.Box; Console.WriteLine($"Text: {block.Text}"); Console.WriteLine($"Position: X={rect.X}, Y={rect.Y}"); Console.WriteLine($"Size: Width={rect.Width}, Height={rect.Height}"); } ``` -------------------------------- ### Language Property Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/ConfigureOptions.md Gets or sets the language for OCR text recognition. The default language is English. ```APIDOC ## Language ### Description Gets or sets the language for OCR text recognition. The default language is English. ### Property - **Language** (string) - Required - The language code for text recognition. Default: "English". ### Supported Languages - "English" - "Chinese" - "Chinesetraditional" - "French" - "German" - "Japan" - "Korean" ### Remarks - Language names are case-sensitive. - The specified language model must be compatible with the ModelPath. ### Example ```csharp ConfigureOptions options = new ConfigureOptions(); options.Language = "Japanese"; // or "Japan" options.Language = "Chinese"; // Alternatively use: options.Language = "Chinesetraditional"; options.Language = "English"; // Default ``` ``` -------------------------------- ### Perform OCR Scan with Spire.OCR Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/Spire.OCR-namespace.md Demonstrates how to initialize OcrScanner, configure dependencies with model path and language, scan an image file, retrieve the text result, and dispose of resources. ```csharp OcrScanner scanner = new OcrScanner(); ConfigureOptions options = new ConfigureOptions(); options.ModelPath = "D:\\win-x64"; options.Language = "English"; scanner.ConfigureDependencies(options); scanner.Scan("image.jpg"); string result = scanner.Text.ToString(); scanner.Dispose(); ``` -------------------------------- ### Configure OCR Scanner Options Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/Spire.OCR-namespace.md Shows how to set up configuration options for the OcrScanner, including the model path, recognition language, and enabling auto-rotation detection. ```csharp ConfigureOptions options = new ConfigureOptions(); options.ModelPath = "D:\\win-x64"; options.Language = "English"; options.AutoRotate = true; ``` -------------------------------- ### OCR Scanning and Result Output Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/Complete-Example.md Demonstrates the complete workflow: initializing and configuring OcrScanner, performing OCR on an image, and saving the results to Markdown and CSV files. Ensure the model path is correctly set and the scanner is disposed after use. ```csharp // Usage OcrScanner scanner = new OcrScanner(); ConfigureOptions options = new ConfigureOptions(); options.ModelPath = @"D:\win-x64"; scanner.ConfigureDependencies(options); scanner.Scan("document.png"); string markdown = OcrResultFormatter.ToMarkdown(scanner.Text); File.WriteAllText("output.md", markdown); string csv = OcrResultFormatter.ToCsv(scanner.Text.Blocks); File.WriteAllText("output.csv", csv); scanner.Dispose(); ``` -------------------------------- ### Basic OCR Scanner Configuration Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/configuration.md Sets up a basic OCR scanner with a specified model path and language. The language can often be omitted if English is the default. ```csharp OcrScanner scanner = new OcrScanner(); ConfigureOptions options = new ConfigureOptions(); options.ModelPath = "D:\\win-x64"; options.Language = "English"; // Default, can be omitted scanner.ConfigureDependencies(options); scanner.Scan("image.jpg"); string result = scanner.Text.ToString(); ``` -------------------------------- ### OcrScanner.Text Property Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/OcrScanner.md Gets the OCR recognition results after scanning an image. The results include all recognized text blocks and metadata. ```APIDOC ## Text ### Description Gets the OCR recognition results after scanning an image. The results are stored in an `IOCRResult` object. ### Property Type `IOCRResult` ### Returns An `IOCRResult` object containing recognized text blocks and metadata from the last scan operation. ### Example ```csharp OcrScanner scanner = new OcrScanner(); ConfigureOptions options = new ConfigureOptions(); options.ModelPath = "D:\\win-x64"; options.Language = "English"; scanner.ConfigureDependencies(options); scanner.Scan(imageFile); IOCRResult result = scanner.Text; string allText = result.ToString(); ``` ``` -------------------------------- ### AutoRotate Property Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/ConfigureOptions.md Gets or sets a value indicating whether the OCR engine should automatically detect and correct image rotation. ```APIDOC ## AutoRotate ### Description Gets or sets a value indicating whether the OCR engine should automatically detect and correct image rotation. ### Property - **AutoRotate** (bool) - Optional - Enable automatic rotation detection and correction. Default: `false`. ### Remarks - When enabled, the scanner automatically detects the orientation of text in the image. - Useful for scanning rotated documents or images at arbitrary angles. - May increase processing time slightly. ### Example ```csharp ConfigureOptions options = new ConfigureOptions(); options.ModelPath = "D:\\win-x64"; options.Language = "English"; options.AutoRotate = true; OcrScanner scanner = new OcrScanner(); scanner.ConfigureDependencies(options); // Now the scanner will handle rotated images scanner.Scan("rotated_image.png"); ``` ``` -------------------------------- ### ModelPath Property Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/ConfigureOptions.md Gets or sets the path to the OCR model directory. This is a required setting for the OCR scanner to function correctly. ```APIDOC ## ModelPath ### Description Gets or sets the path to the OCR model directory. The model files must be downloaded separately. ### Property - **ModelPath** (string) - Required - Directory path containing OCR model files. ### Remarks - This property is required and must be set before configuring the scanner. - The path should point to the directory containing the model files (e.g., "D:\\win-x64"). - On Linux/macOS, use forward slashes or appropriate platform paths. ### Example ```csharp ConfigureOptions options = new ConfigureOptions(); options.ModelPath = "D:\\win-x64"; // Windows path // Or for cross-platform: options.ModelPath = "/opt/ocr/models"; // Linux path ``` ``` -------------------------------- ### Create OcrScanner Instance Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/OcrScanner.md Instantiates the OcrScanner class with default settings. This is the first step before configuring and using the scanner. ```csharp OcrScanner scanner = new OcrScanner(); ``` -------------------------------- ### Spire.OCR for .NET File Structure Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/MANIFEST.md Illustrates the directory layout for the Spire.OCR for .NET project documentation, categorizing files by their purpose. ```text output/ ├── README.md (Overview & Quick Start) ├── REFERENCE-INDEX.md (Master Navigation Index) ├── configuration.md (Configuration Guide) ├── types.md (Type Reference) ├── MANIFEST.md (This file) └── api-reference/ (Class & Method References) ├── Spire.OCR-namespace.md (Namespace overview) ├── OcrScanner.md (Main class) ├── ConfigureOptions.md (Config class) ├── IOCRResult.md (Result interface) ├── IOCRTextBlock.md (Block interface) ├── VisualTextAligner.md (Utility class) ├── Complete-Example.md (C# examples) └── VB.NET-Examples.md (VB.NET examples) ``` -------------------------------- ### Scan Image from Network Stream Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/Complete-Example.md Extracts text from an image fetched from a URL. This example uses HttpClient to download the image into a stream before processing. ```csharp using (HttpClient client = new HttpClient()) { string imageUrl = "https://example.com/image.jpg"; using (HttpResponseMessage response = await client.GetAsync(imageUrl)) { using (Stream contentStream = await response.Content.ReadAsStreamAsync()) { OcrScanner scanner = new OcrScanner(); ConfigureOptions options = new ConfigureOptions(); options.ModelPath = @"D:\win-x64"; scanner.ConfigureDependencies(options); scanner.Scan(contentStream, OCRImageFormat.Jpg); string result = scanner.Text.ToString(); scanner.Dispose(); } } } ``` -------------------------------- ### Build Output String with StringBuilder Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/types.md Demonstrates using System.Text.StringBuilder to efficiently construct a string from multiple text blocks by traversing the OCR results recursively. ```csharp StringBuilder sb = new StringBuilder(); void TraverseBlocks(IOCRTextBlock[] blocks) { foreach (IOCRTextBlock block in blocks) { sb.Append(block.Text); sb.AppendLine(); if (block.TextBlock != null) { TraverseBlocks(block.TextBlock); } } } TraverseBlocks(scanner.Text.Blocks); string result = sb.ToString(); ``` -------------------------------- ### ConfigureOptions() Constructor Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/ConfigureOptions.md Creates a new instance of the ConfigureOptions class with default settings. This is the entry point for configuring OCR scanner dependencies. ```APIDOC ## ConfigureOptions() ### Description Creates a new instance of the `ConfigureOptions` class with default settings. ### Parameters None ### Returns A new `ConfigureOptions` instance. ### Example ```csharp // Create configuration options with defaults ConfigureOptions options = new ConfigureOptions(); ``` ``` -------------------------------- ### Simple Text Extraction using Scanner.Text Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/VisualTextAligner.md Demonstrates how to get raw concatenated text directly from the OcrScanner's Text property, without visual alignment. ```csharp // Gets raw concatenated text string plainText = scanner.Text.ToString(); ``` -------------------------------- ### Get Aligned Text as String Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/VisualTextAligner.md Use the ToString() method to retrieve the visually aligned and formatted text. This method preserves the original document's spatial layout. ```csharp OcrScanner scanner = new OcrScanner(); ConfigureOptions options = new ConfigureOptions(); options.ModelPath = "D:\\win-x64"; options.Language = "English"; options.AutoRotate = true; scanner.ConfigureDependencies(options); scanner.Scan("rotated_document.png"); // Create aligner and get formatted text VisualTextAligner aligner = new VisualTextAligner(scanner.Text); string alignedText = aligner.ToString(); // Save to file File.WriteAllText("output.txt", alignedText); // Or display Console.WriteLine(alignedText); ``` -------------------------------- ### OcrScanner.ConfigureDependencies Method Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/OcrScanner.md Configures the OCR scanner with specified settings, including the model path and language for recognition. ```APIDOC ## ConfigureDependencies ### Description Configures the OCR scanner with specified settings including model path and language. ### Method Signature `public void ConfigureDependencies(ConfigureOptions options)` ### Parameters #### Parameters - **options** (`ConfigureOptions`) - Required - Configuration options object containing ModelPath, Language, and other settings. ### Returns `void` ### Example ```csharp OcrScanner scanner = new OcrScanner(); ConfigureOptions configureOptions = new ConfigureOptions(); configureOptions.ModelPath = "D:\\win-x64"; configureOptions.Language = "English"; configureOptions.AutoRotate = true; scanner.ConfigureDependencies(configureOptions); ``` ``` -------------------------------- ### Extract Text from Rotated Images with Auto-Rotation Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/CS-Examples/ocr_cs.md This example demonstrates how to enable the auto-rotation feature in OcrScanner to extract text from images that may be rotated. The ModelPath and Language should be configured as needed. ```csharp OcrScanner scanner = new OcrScanner(); ConfigureOptions configureOptions = new ConfigureOptions(); configureOptions.ModelPath = "D:\\win-x64"; configureOptions.Language = "English"; configureOptions.AutoRotate = true; scanner.ConfigureDependencies(configureOptions); scanner.Scan(imageFile); VisualTextAligner visualText = new VisualTextAligner(scanner.Text); string scannnedText = visualText.ToString(); scanner.Dispose(); ``` -------------------------------- ### Scan Image and Extract Text Workflow Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/REFERENCE-INDEX.md Steps to create an OcrScanner instance, configure it with model path and language, scan an image file, and access the extracted text. Remember to dispose of the scanner when done. ```csharp 1. Create OcrScanner instance 2. Create ConfigureOptions with ModelPath and Language 3. Call OcrScanner.ConfigureDependencies() 4. Call OcrScanner.Scan(filePath) 5. Access scanner.Text.ToString() for all text 6. Call scanner.Dispose() ``` -------------------------------- ### Basic Image Scanning from File Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/Complete-Example.md Scans a JPG image file and extracts text. Ensure the model path is correctly set. ```csharp using Spire.OCR; using System; using System.IO; public class BasicExample { public static void Main() { OcrScanner scanner = new OcrScanner(); // Configure ConfigureOptions options = new ConfigureOptions(); options.ModelPath = @"D:\win-x64"; options.Language = "English"; scanner.ConfigureDependencies(options); // Scan and extract scanner.Scan("document.jpg"); string result = scanner.Text.ToString(); Console.WriteLine(result); scanner.Dispose(); } } ``` -------------------------------- ### Getting All Text as String Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/IOCRResult.md Retrieves the complete recognized text from the OCR result as a single concatenated string. This is useful for obtaining the full text content without structural details. ```APIDOC ## Get All Text ### Description Returns the complete recognized text from the OCR result as a single concatenated string. ### Method GET ### Endpoint /ocrresult/tostring ### Parameters #### Query Parameters None #### Request Body None ### Response #### Success Response (200) - **Result** (`string`) - A string containing all recognized text from the image ### Response Example { "Result": "This is the complete recognized text from the scanned document." } ``` -------------------------------- ### Basic OCR Scan in C# Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/README.md Demonstrates the basic usage of Spire.OCR to scan an image file and retrieve recognized text. Ensure the ModelPath points to your downloaded OCR models. ```csharp using Spire.OCR; using System; using System.IO; // Create scanner OcrScanner scanner = new OcrScanner(); // Configure ConfigureOptions options = new ConfigureOptions(); options.ModelPath = "D:\\win-x64"; // Path to downloaded models options.Language = "English"; scanner.ConfigureDependencies(options); // Scan image scanner.Scan("image.jpg"); // Get results string recognizedText = scanner.Text.ToString(); Console.WriteLine(recognizedText); // Cleanup scanner.Dispose(); ``` -------------------------------- ### Get All Recognized Text as String Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/IOCRResult.md Retrieves the entire recognized text from an OCR scan as a single concatenated string. This is useful for simple text extraction without needing positional information. ```csharp OcrScanner scanner = new OcrScanner(); ConfigureOptions options = new ConfigureOptions(); options.ModelPath = "D:\\win-x64"; scanner.ConfigureDependencies(options); scanner.Scan("image.png"); // Get all text as a single string string allText = scanner.Text.ToString(); Console.WriteLine(allText); // Or save to file File.WriteAllText("output.txt", allText); ``` -------------------------------- ### Create VisualTextAligner Instance Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/VisualTextAligner.md Instantiate VisualTextAligner with IOCRResult. This is useful for initializing the aligner with OCR data obtained from an OcrScanner. ```csharp OcrScanner scanner = new OcrScanner(); ConfigureOptions options = new ConfigureOptions(); options.ModelPath = "D:\\win-x64"; options.Language = "English"; options.AutoRotate = true; scanner.ConfigureDependencies(options); scanner.Scan("rotated_image.png"); // Create text aligner with the OCR results VisualTextAligner aligner = new VisualTextAligner(scanner.Text); ``` -------------------------------- ### Scan Image from Stream with Specified Format Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/types.md Demonstrates how to scan an image from a file stream, specifying the image format using the OCRImageFormat enumeration. Ensure the OcrScanner and ConfigureOptions are properly initialized. ```csharp OcrScanner scanner = new OcrScanner(); ConfigureOptions options = new ConfigureOptions(); options.ModelPath = "D:\\win-x64"; options.Language = "English"; scanner.ConfigureDependencies(options); // Specify format when scanning from stream using (FileStream stream = File.OpenRead("image.jpg")) { scanner.Scan(stream, OCRImageFormat.Jpg); } string result = scanner.Text.ToString(); ``` -------------------------------- ### Get Visually Aligned Text Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/VisualTextAligner.md Instantiate VisualTextAligner with the OCR result text to preserve visual layout and positioning. This is useful for extracting text as a flat string that reflects the document's structure. ```csharp // Gets text with layout preserved VisualTextAligner aligner = new VisualTextAligner(scanner.Text); string alignedText = aligner.ToString(); ``` -------------------------------- ### Load OCR Configuration from JSON Settings Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/configuration.md Defines a configuration class and a method to load OCR settings from a JSON file. This promotes externalizing configuration. ```csharp public class OcrConfiguration { public string ModelPath { get; set; } public string Language { get; set; } public bool AutoRotate { get; set; } public static OcrConfiguration LoadFromJson(string jsonPath) { string json = File.ReadAllText(jsonPath); return JsonConvert.DeserializeObject(json); } } // appsettings.json /* { "Ocr": { "ModelPath": "D:\\win-x64", "Language": "English", "AutoRotate": false } } */ // Usage OcrConfiguration config = OcrConfiguration.LoadFromJson("appsettings.json"); ConfigureOptions options = new ConfigureOptions(); options.ModelPath = config.ModelPath; options.Language = config.Language; options.AutoRotate = config.AutoRotate; OcrScanner scanner = new OcrScanner(); scanner.ConfigureDependencies(options); ``` -------------------------------- ### Using Statements for Resource Management in VB.NET Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/VB.NET-Examples.md Illustrates the 'Using' statement for ensuring proper disposal of resources like FileStream objects. This guarantees that resources are released even if errors occur. ```vbnet Using stream As FileStream = File.OpenRead("image.jpg") scanner.Scan(stream, OCRImageFormat.Jpg) End Using ``` -------------------------------- ### VisualTextAligner Constructor Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/VisualTextAligner.md Creates a new instance of the VisualTextAligner class, initializing it with the provided OCR results. This prepares the aligner to format the recognized text. ```APIDOC ## VisualTextAligner(IOCRResult) ### Description Creates a new instance of the `VisualTextAligner` class with OCR results to be aligned and formatted. ### Method Signature `public VisualTextAligner(IOCRResult ocrResult)` ### Parameters #### Parameters - **ocrResult** (`IOCRResult`) - Required - The OCR result object containing text blocks to align. ### Example ```csharp // Assuming scanner is an initialized OcrScanner instance and scanner.Text contains IOCRResult VisualTextAligner aligner = new VisualTextAligner(scanner.Text); ``` ``` -------------------------------- ### Configure OcrScanner Dependencies Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/OcrScanner.md Configures the OCR scanner with essential settings like the model path and language. Ensure the model files are downloaded and the path is correctly specified. ```csharp OcrScanner scanner = new OcrScanner(); ConfigureOptions configureOptions = new ConfigureOptions(); configureOptions.ModelPath = "D:\\win-x64"; configureOptions.Language = "English"; configureOptions.AutoRotate = true; scanner.ConfigureDependencies(configureOptions); ``` -------------------------------- ### Scan Image and Access Text Blocks Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/types.md Demonstrates how to initialize and configure the OcrScanner, scan an image file, and iterate through the detected text blocks to access their properties like text content, bounding box, and level. ```csharp OcrScanner scanner = new OcrScanner(); ConfigureOptions options = new ConfigureOptions(); options.ModelPath = "D:\\win-x64"; options.Language = "English"; scanner.ConfigureDependencies(options); scanner.Scan("image.png"); IOCRTextBlock[] blocks = scanner.Text.Blocks; foreach (IOCRTextBlock block in blocks) { // Access properties string text = block.Text; Rectangle box = block.Box; TextBlockType level = block.Level; IOCRTextBlock[] children = block.TextBlock; Console.WriteLine($"Text: {text}"); Console.WriteLine($"Position: ({box.X}, {box.Y})"); Console.WriteLine($"Size: {box.Width}x{box.Height}"); Console.WriteLine($"Level: {level}"); } ``` -------------------------------- ### Scan Image and Save Text to File (VB.NET) Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/VB.NET-Examples.md Scans a PNG image and saves the extracted text to a text file. Requires the model path to be set. ```vbnet Imports Spire.OCR Imports System Imports System.IO Public Class SaveExample Public Shared Sub Main() Dim scanner As New OcrScanner() Dim options As New ConfigureOptions() options.ModelPath = "D:\win-x64" options.Language = "English" scanner.ConfigureDependencies(options) scanner.Scan("image.png") Dim output As String = scanner.Text.ToString() File.WriteAllText("output.txt", output) scanner.Dispose() End Sub End Class ``` -------------------------------- ### Configure OCR with Auto-Rotation and VisualTextAligner Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/configuration.md Combines OCR configuration with auto-rotation enabled and uses VisualTextAligner for improved text formatting. Ensure the model path and language are correctly set. ```csharp ConfigureOptions options = new ConfigureOptions(); options.ModelPath = "D:\\win-x64"; options.Language = "English"; options.AutoRotate = true; OcrScanner scanner = new OcrScanner(); scanner.ConfigureDependencies(options); scanner.Scan("rotated_document.png"); // Use aligner for better formatting VisualTextAligner aligner = new VisualTextAligner(scanner.Text); string result = aligner.ToString(); File.WriteAllText("output.txt", result); ``` -------------------------------- ### Switch OCR Language Between Scans Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/Complete-Example.md Demonstrates how to use the same OcrScanner instance to process documents in multiple languages by reconfiguring options between scans. This is efficient for batch processing multilingual documents. ```csharp OcrScanner scanner = new OcrScanner(); ConfigureOptions options = new ConfigureOptions(); options.ModelPath = @"D:\win-x64"; scanner.ConfigureDependencies(options); // Scan English document options.Language = "English"; scanner.ConfigureDependencies(options); scanner.Scan("english.png"); string englishText = scanner.Text.ToString(); Console.WriteLine("English: " + englishText); // Scan Japanese document with same scanner options.Language = "Japan"; scanner.ConfigureDependencies(options); scanner.Scan("japanese.png"); string japaneseText = scanner.Text.ToString(); Console.WriteLine("Japanese: " + japaneseText); // Scan Chinese document options.Language = "Chinese"; scanner.ConfigureDependencies(options); scanner.Scan("chinese.png"); string chineseText = scanner.Text.ToString(); Console.WriteLine("Chinese: " + chineseText); scanner.Dispose(); ``` -------------------------------- ### OcrScanner Constructor Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/OcrScanner.md Creates a new instance of the OcrScanner class with default settings. ```APIDOC ## OcrScanner() ### Description Creates a new instance of the `OcrScanner` class with default settings. ### Parameters None ### Returns A new `OcrScanner` instance. ### Example ```csharp // Create a new OCR scanner OcrScanner scanner = new OcrScanner(); ``` ``` -------------------------------- ### Handle Rotated Images Workflow Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/REFERENCE-INDEX.md This workflow demonstrates how to enable automatic image rotation correction by setting `ConfigureOptions.AutoRotate` to true. It then shows how to scan the image and use `VisualTextAligner` for formatted output. ```csharp 1. Set ConfigureOptions.AutoRotate = true 2. Scan image 3. Create VisualTextAligner with scanner.Text 4. Call aligner.ToString() for formatted output ``` -------------------------------- ### Iterate Through Text Blocks (VB.NET) Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/VB.NET-Examples.md Scans an image and iterates through the detected text blocks, printing their text, level, and bounding box. Requires model configuration. ```vbnet Imports Spire.OCR Imports System Imports System.IO Public Class BlockIterationExample Public Shared Sub Main() Dim scanner As New OcrScanner() Dim options As New ConfigureOptions() options.ModelPath = "D:\win-x64" scanner.ConfigureDependencies(options) scanner.Scan("document.png") Dim blocks As IOCRTextBlock() = scanner.Text.Blocks For Each block As IOCRTextBlock In blocks Console.WriteLine($"Text: {block.Text}") Console.WriteLine($"Level: {block.Level}") Console.WriteLine($"Box: {block.Box}") Next scanner.Dispose() End Sub End Class ``` -------------------------------- ### Batch Process Multiple Images Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/api-reference/Complete-Example.md Scans a batch of images sequentially and saves the results to text files. Ensure the model path and language are correctly configured. ```csharp public class BatchProcessor { public static void ProcessImageBatch(string[] imagePaths) { OcrScanner scanner = new OcrScanner(); ConfigureOptions options = new ConfigureOptions(); options.ModelPath = @"D:\win-x64"; options.Language = "English"; scanner.ConfigureDependencies(options); foreach (string imagePath in imagePaths) { try { scanner.Scan(imagePath); string result = scanner.Text.ToString(); string outputPath = Path.ChangeExtension(imagePath, ".txt"); File.WriteAllText(outputPath, result); Console.WriteLine($"Processed: {imagePath}"); } catch (Exception ex) { Console.WriteLine($"Error processing {imagePath}: {ex.Message}"); } } scanner.Dispose(); } } // Usage string[] images = Directory.GetFiles("images", "*.jpg"); BatchProcessor.ProcessImageBatch(images); ``` -------------------------------- ### Documentation Version History Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/_autodocs/MANIFEST.md Presents a table detailing the version, date, and content of the Spire.OCR for .NET documentation releases. ```text | Version | Date | Content | |---------|------|---------| | 1.0 | June 10, 2026 | Initial complete reference | ``` -------------------------------- ### Extract Text Coordinates from Image using OCR Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/CS-Examples/ocr_cs.md This snippet shows how to initialize the OcrScanner, configure model path and language, scan an image, and retrieve text blocks with their bounding box coordinates. Ensure the ModelPath is set to your actual model directory. ```csharp OcrScanner scanner = new OcrScanner(); ConfigureOptions configureOptions = new ConfigureOptions(); configureOptions.ModelPath = "D:\\win-x64"; configureOptions.Language = "English"; scanner.ConfigureDependencies(configureOptions); scanner.Scan(imageFile); IOCRTextBlock[] blocks = scanner.Text.Blocks; string scannnedText = PrintTextBlocks(blocks); ``` ```csharp private static string PrintTextBlocks(IOCRTextBlock[] blocks, StringBuilder sb = null) { if (sb == null || sb.Length == 0) sb = new StringBuilder(); if (blocks != null && blocks.Count() > 0) { foreach (var block in blocks) { Rectangle rectangle = block.Box; string t1 = string.Format("Rectangle : [{0}, {1}, {2}, {3}] , ", rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); string t2 = string.Format("Level ({0}): {1}", block.Level.ToString(), block.Text); string text = t1 + t2; text = text + "\n"; sb.Append(text); PrintTextBlocks(block.TextBlock, sb); if (block.Level == TextBlockType.Line) sb.Append("\n"); } } return sb.ToString(); } ``` -------------------------------- ### VB.NET OCR Scanning and AI Configuration Update Source: https://github.com/eiceblue/spire.ocr-for-.net/blob/main/VB-Examples/ocr_vb.md This VB.NET code snippet shows how to update an OCR configuration XML file and then perform OCR on an image using Spire.OCR. It's useful for scenarios where AI model details need to be dynamically set before image processing. ```vbnet Public Partial Class Form1 : Inherits Form Public Sub New() InitializeComponent() End Sub Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Dim filename As String = "../../../..\/Data/JapaneseSample.png" Dim outputFile As String = "ScanImageWithAI.txt" Dim filePath As String = "D:\\AI\ocr.xml" Dim newModel As String = "AIModel" Dim newApiKey As String = "ApiKey" Dim newApiUrl As String = "ApiUrl" UpdateOcrConfig(filePath, newModel, newApiKey, newApiUrl) ScanImg(filename, outputFile) TxtViewer(outputFile) End Sub Public Shared Sub ScanImg(ByVal filename As String, ByVal outputFile As String) Dim scanner As OcrScanner = New OcrScanner() Dim configureOptions As ConfigureOptions = New ConfigureOptions() configureOptions.ModelPath = "D:\\AI" configureOptions.Language = "Japanese" scanner.ConfigureDependencies(configureOptions) scanner.Scan(filename) File.WriteAllText(outputFile, scanner.Text.ToString()) End Sub Public Shared Sub UpdateOcrConfig(ByVal filePath As String, ByVal model As String, ByVal apiKey As String, ByVal apiUrl As String) Dim doc As XmlDocument = New XmlDocument() doc.Load(filePath) Dim modelNode As XmlNode = doc.SelectSingleNode("/ocr/configs/model") Dim apiKeyNode As XmlNode = doc.SelectSingleNode("/ocr/configs/apiKey") Dim apiUrlNode As XmlNode = doc.SelectSingleNode("/ocr/configs/apiUrl") If modelNode <> Nothing Then modelNode.InnerText = model If apiKeyNode <> Nothing Then apiKeyNode.InnerText = apiKey If apiUrlNode <> Nothing Then apiUrlNode.InnerText = apiUrl doc.Save(filePath) End Sub Private Sub TxtViewer(ByVal outputFile As String) System.Diagnostics.Process.Start(outputFile) End Sub End Class ```