How to Export OCR Results to Multiple Formats Using Aspose.OCR

How to Export OCR Results to Multiple Formats Using Aspose.OCR

Business, legal, and compliance workflows often require OCR results in multiple digital formats for integration, reporting, and archiving. Aspose.OCR for .NET provides flexible export to common formats such as TXT, DOCX, XLSX, PDF, and JSON with just one method call.

Real-World Problem

Data extracted via OCR needs to be shared with colleagues, imported into ERPs or BI tools, archived, or processed further. Manual reformatting wastes time and risks introducing errors.

Solution Overview

Aspose.OCR lets you choose the output format for each recognition result—whether plain text, formatted Word, Excel tables, searchable PDF, or structured JSON. Exporting is simple, flexible, and integrates with automated workflows.


Prerequisites

  1. Visual Studio 2019 or later
  2. .NET 6.0 or later (or .NET Framework 4.6.2+)
  3. Aspose.OCR for .NET from NuGet
  4. Basic C# programming skills
PM> Install-Package Aspose.OCR

Step-by-Step Implementation

Step 1: Install and Configure Aspose.OCR

using Aspose.OCR;

Step 2: Recognize Text, Tables, or Images

OcrInput input = new OcrInput(InputType.SingleImage);
input.Add("invoice.png");
RecognitionSettings settings = new RecognitionSettings();
settings.Language = Language.English;
AsposeOcr ocr = new AsposeOcr();
List<RecognitionResult> results = ocr.Recognize(input, settings);

Step 3: Export OCR Results to Multiple Formats

foreach (RecognitionResult result in results)
{
    result.Save("output.txt", SaveFormat.Text);   // Plain text
    result.Save("output.docx", SaveFormat.Docx);  // Microsoft Word
    result.Save("output.xlsx", SaveFormat.Xlsx);  // Excel table
    result.Save("output.pdf", SaveFormat.Pdf);    // Searchable PDF
    result.Save("output.json", SaveFormat.Json);  // Structured JSON
}

Step 4: Automate Batch Export

Export all processed images from a folder to desired formats:

foreach (string file in Directory.GetFiles("./input", "*.jpg"))
{
    input.Add(file);
}
// Run OCR, then export as above

Step 5: Handle Errors and Validate Exports

try
{
    // Export logic
}
catch (Exception ex)
{
    Console.WriteLine($"Export error: {ex.Message}");
}

Step 6: Integrate with Downstream Workflows

Use exported files in:

  • Reporting and BI dashboards (Excel, JSON)
  • Document management (PDF, DOCX)
  • Automation scripts (TXT, JSON)

Step 7: Complete Example

using Aspose.OCR;
using System;
using System.Collections.Generic;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        try
        {
            OcrInput input = new OcrInput(InputType.SingleImage);
            input.Add("invoice.png");
            RecognitionSettings settings = new RecognitionSettings();
            settings.Language = Language.English;
            AsposeOcr ocr = new AsposeOcr();
            List<RecognitionResult> results = ocr.Recognize(input, settings);

            foreach (RecognitionResult result in results)
            {
                result.Save("output.txt", SaveFormat.Text);
                result.Save("output.docx", SaveFormat.Docx);
                result.Save("output.xlsx", SaveFormat.Xlsx);
                result.Save("output.pdf", SaveFormat.Pdf);
                result.Save("output.json", SaveFormat.Json);
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Export error: {ex.Message}");
        }
    }
}

Use Cases and Applications

ERP/Database Integration

Import Excel, JSON, or TXT output for automatic posting and search.

Document Management and Archiving

Create searchable, compliant records in PDF, DOCX, or TXT.

Business Reporting

Populate BI dashboards or share results in multiple formats.


Common Challenges and Solutions

Challenge 1: Choosing the Right Format for Each Use

Solution: Map outputs to business requirements and audience.

Challenge 2: Export Errors or File Overwrites

Solution: Add file existence checks and timestamped names.

Challenge 3: Large-Scale Batch Exports

Solution: Automate and schedule batch jobs; monitor export folder health.


Performance Considerations

  • Exporting large files to multiple formats may increase processing time
  • Monitor disk space and folder structure
  • Validate exported files regularly

Best Practices

  1. Name exports for traceability and search
  2. Secure and backup exported files
  3. Test with real-world business samples
  4. Update Aspose.OCR for latest export features

Advanced Scenarios

Scenario 1: Custom Naming or Export Paths

string customName = Path.GetFileNameWithoutExtension(result.FileName) + "_ocr";
result.Save($"./exports/{customName}.pdf", SaveFormat.Pdf);

Scenario 2: Export Only Specific Data (e.g. Tables)

if (result.HasTable)
    result.Save("output_tables.xlsx", SaveFormat.Xlsx);

Conclusion

Aspose.OCR for .NET makes it easy to deliver OCR results in the formats your workflows, colleagues, and systems need—boosting automation, sharing, and integration with minimal effort.

See the Aspose.OCR for .NET API Reference for the latest on supported export formats and advanced features.

 English