ByteScout Document Parser SDK - C# - Parse with OCR - ByteScout

ByteScout Document Parser SDK – C# – Parse with OCR

  • Home
  • /
  • Articles
  • /
  • ByteScout Document Parser SDK – C# – Parse with OCR

How to parse with OCR in C# with ByteScout Document Parser SDK

How to code in C# to parse with OCR with this step-by-step tutorial

Every ByteScout tool contains example C# source codes that you can find here or in the folder with installed ByteScout product. ByteScout Document Parser SDK: the robost offline data extraction platform for template based data extraction and processing. Supports high load with millions of documents as input. Templates can be quickly created and updated with no special technical knowledge required. It can parse with OCR in C#.

This code snippet below for ByteScout Document Parser SDK works best when you need to quickly parse with OCR in your C# application. Follow the instructions from the scratch to work and copy the C# code. Enjoy writing a code with ready-to-use sample codes in C#.

Trial version of ByteScout Document Parser SDK is available for free. Source code samples are included to help you with your C# app.

Try it today: Get 60 Day Free Trial or sign up for Web API

<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="15.0" xmlns=""> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <ProjectGuid>{A73776C6-D2B2-4E37-B852-06C6454D1B5B}</ProjectGuid> <OutputType>Exe</OutputType> <RootNamespace>ParseWithOCR</RootNamespace> <AssemblyName>ParseWithOCR</AssemblyName> <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <FileAlignment>512</FileAlignment> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PlatformTarget>AnyCPU</PlatformTarget> <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <Optimize>false</Optimize> <OutputPath>bin\Debug\</OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PlatformTarget>AnyCPU</PlatformTarget> <DebugType>pdbonly</DebugType> <Optimize>true</Optimize> <OutputPath>bin\Release\</OutputPath> <DefineConstants>TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> <Reference Include="ByteScout.DocumentParser, Version=, Culture=neutral, PublicKeyToken=f7dd1bd9d40a50eb, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> <HintPath>c:\Program Files\ByteScout Document Parser SDK\net40\ByteScout.DocumentParser.dll</HintPath> </Reference> <Reference Include="System" /> <Reference Include="System.Core" /> <Reference Include="System.Xml.Linq" /> <Reference Include="System.Data" /> <Reference Include="System.Xml" /> </ItemGroup> <ItemGroup> <Compile Include="Program.cs" /> </ItemGroup> <ItemGroup> <Content Include="..\..\DigitalOcean-scanned.jpg"> <Link>DigitalOcean-scanned.jpg</Link> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> </ItemGroup> <ItemGroup> <None Include="..\..\_Sample Templates\DigitalOcean.yml"> <Link>DigitalOcean.yml</Link> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </None> </ItemGroup> <ItemGroup> <Folder Include="Properties\" /> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> </Project>

Try it today: Get 60 Day Free Trial or sign up for Web API

Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.28729.10 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ParseWithOCR", "ParseWithOCR.csproj", "{A73776C6-D2B2-4E37-B852-06C6454D1B5B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {A73776C6-D2B2-4E37-B852-06C6454D1B5B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {A73776C6-D2B2-4E37-B852-06C6454D1B5B}.Debug|Any CPU.Build.0 = Debug|Any CPU {A73776C6-D2B2-4E37-B852-06C6454D1B5B}.Release|Any CPU.ActiveCfg = Release|Any CPU {A73776C6-D2B2-4E37-B852-06C6454D1B5B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {7E6DAA79-020B-421A-844A-5FE05EFC9B15} EndGlobalSection EndGlobal

Try it today: Get 60 Day Free Trial or sign up for Web API

using System; using ByteScout.DocumentParser; // This example demonstrates parsing of scanned documents // using the Optical Character Recognition (OCR). namespace GeneralExample { class Program { static void Main(string[] args) { string template = @".\DigitalOcean.yml"; string inputDocument = @".\DigitalOcean-scanned.jpg"; // Create and activate DocumentParser instance using (DocumentParser documentParser = new DocumentParser("demo", "demo")) { // Enable Optical Character Recognition (OCR) in Auto mode // (DocumentParser automatically detects if OCR is required). documentParser.OCRMode = OCRMode.Auto; // Set PDF document rendering resolution documentParser.OCRResolution = 300; // Set the location of OCR language data files documentParser.OCRLanguageDataFolder = @"c:\Program Files\ByteScout Document Parser SDK\ocrdata"; // Set OCR language // "eng" for english, "deu" for German, "fra" for French, etc. - according to files in "ocrdata" folder documentParser.OCRLanguage = "eng"; // Find more language files at // Note: The OCRLanguage can be overridden in a template. // See the Template Creation Guide. // You can also apply various preprocessing filters // to improve the recognition on low-quality scans. // Automatically deskew skewed scans //documentParser.OCRImagePreprocessingFilters.AddDeskew(); // Remove vertical or horizontal lines (sometimes helps to avoid OCR engine's page segmentation errors) //documentParser.OCRImagePreprocessingFilters.AddVerticalLinesRemover(); //documentParser.OCRImagePreprocessingFilters.AddHorizontalLinesRemover(); // Repair broken letters //documentParser.OCRImagePreprocessingFilters.AddDilate(); // Remove noise //documentParser.OCRImagePreprocessingFilters.AddMedian(); // Apply Gamma Correction //documentParser.OCRImagePreprocessingFilters.AddGammaCorrection(1.4); // Add Contrast //documentParser.OCRImagePreprocessingFilters.AddContrast(20); // Load template documentParser.AddTemplate(template); Console.WriteLine("Template loaded."); Console.WriteLine(); Console.WriteLine({code}quot;Parsing \"{inputDocument}\" with OCR..."); Console.WriteLine(); // Parse document data to JSON format string jsonString = documentParser.ParseDocument(inputDocument, OutputFormat.JSON); // Display parsed data in console Console.WriteLine("Parsed data in JSON format:"); Console.WriteLine(); Console.WriteLine(jsonString); } Console.WriteLine(); Console.WriteLine("Press any key to continue..."); Console.ReadLine(); } } }

Try it today: Get 60 Day Free Trial or sign up for Web API


Get 60 Day Free Trial or Visit ByteScout Document Parser SDK page

Explore ByteScout Document Parser SDK documentation


Sign Up for free Web API key

Explore Web API Documentation