2

I need to be able to import and process a variety of different images and documents. I need a tool or library that will ingest the file and perform OCR if necessary, but save it out as a standardized PDF file for archiving purposes (PDF/A). Is there a tool or .NET library that can achieve this? If the document is already searchable, it should not OCR it again.

2 Answers 2

1

You may want to consider trying the Leadtools SDK. Their DocumentConverter is designed especially for this type of workflow. You can take any document or image format, vector based or raster, and convert to any other document or image format, and OCR is performed automatically based on your settings. Below you can find a quick snippet for converting a directory of various files to PDF documents in another directory. Just as a disclaimer, I work for the vendor of this product.

using (DocumentConverter documentConverter = new DocumentConverter())
{
    string inputDirectory = @"C:\temp\input files";
    string outputDirectory = @"C:\temp\output documents";
    string[] inputFiles = Directory.GetFiles(inputDirectory);

    // Required for document output
    var documentWriter = new DocumentWriter();
    documentConverter.SetDocumentWriterInstance(documentWriter);

    // Optional for Raster -> Searchable Vector
    var ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD);
    ocrEngine.Startup(null, documentWriter, null, null);
    documentConverter.SetOcrEngineInstance(ocrEngine, true);

    // Look through each file in the input directory
    foreach (var filename in inputFiles)
    {
        // Create a DocumentConverterJobData that holds the necessary information
        var jobData = new DocumentConverterJobData();
        jobData.InputDocumentFileName = filename;
        jobData.DocumentFormat = DocumentFormat.Pdf;
        jobData.OutputDocumentFileName = Path.Combine(outputDirectory, Path.GetFileNameWithoutExtension(filename) + ".pdf");

        // Create a job with the necessary jobData and execute it
        var job = documentConverter.Jobs.CreateJob(jobData);
        documentConverter.Jobs.RunJobAsync(job);
    }
}
2
  • Hello @JClark742, thank you for your answer. I have a couple follow up questions: Is this a commercial library? If so, where can I see pricing and can I try it for free before buying? Does this work cross platform via .NET 5? Is there a Nuget library I can use?
    – norbpat563
    Feb 23, 2021 at 13:24
  • LEADTOOLS is a commercial library that you can download and try for free here: leadtools.com/downloads. You can also find our NuGet packages here: nuget.org/packages/Leadtools.Document.Sdk. This is supported on .NET and you can find our basic pricing outline here: leadtools.com/sdk/product-overview.
    – JClark742
    Feb 23, 2021 at 15:18
1

Syncfusion’s Essential PDF (.NET PDF library) supports OCR by using the Tesseract open-source engine. A scanned paper document containing raster images is converted to a searchable and selectable document with a few lines of code. Please refer to the below links for more information,

UG: https://help.syncfusion.com/file-formats/pdf/working-with-ocr/dot-net-framework

KB: https://www.syncfusion.com/kb/9144/how-to-convert-scanned-image-to-searchable-pdf-by-processing-ocr

NuGet information: https://help.syncfusion.com/file-formats/pdf/nuget-packages-required#pdf-ocr

Please refer the below code snippet to OCR a PDF document and save with PDF/A1b conformance.

using Syncfusion.OCRProcessor;

using Syncfusion.Pdf.Parsing;

using System.IO;

static void Main(string[] args)

    {
        string path = Path.GetFullPath(@"../../Tesseract_bin/x86/");

        using (OCRProcessor processor = new OCRProcessor(path))

        {
            processor.Settings.TesseractVersion = TesseractVersion.Version4_0;
            //Load a PDF document 

            PdfLoadedDocument lDoc = new PdfLoadedDocument("../../Region.pdf");

            lDoc.Conformance = Syncfusion.Pdf.PdfConformanceLevel.Pdf_A1B;

            //Set OCR language to process 

            processor.Settings.Language = Languages.English;

            
            //Process OCR by providing the PDF document and tesseract data, and enabling the isMemoryOptimized property

            processor.PerformOCR(lDoc, @"../../LanguagePack/", true);

            //Save the OCR processed PDF document in the disk 

            lDoc.Save("Sample.pdf");

            lDoc.Close(true);

        }
    }

We have also provided the support for PDF to PDF/A conversion in our Syncfusion PDF library, please refer the below link,

PDF to PDF/A: https://help.syncfusion.com/file-formats/pdf/working-with-pdf-conformance#pdf-to-pdfa-conversion

More PDF Examples: https://ej2.syncfusion.com/aspnetmvc/PDF/Default#/material

The whole suite of controls is available for free (commercial applications also) through the community license program if you qualify. The community license is the full product with no limitations or watermarks.

Note: I work for Syncfusion.

Regards,

Gowtham

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.