ByteScout Document Parser SDK - C# - Create Custom Template - ByteScout

ByteScout Document Parser SDK – C# – Create Custom Template

  • Home
  • /
  • Articles
  • /
  • ByteScout Document Parser SDK – C# – Create Custom Template

How to create custom template in C# with ByteScout Document Parser SDK

This tutorial will show how to create custom template in C#

The coding tutorials are designed to help you test the features without need to write your own code. ByteScout Document Parser SDK is the template based data extraction engine can process thousands and millions of documents per day based on templates. Can work online and offline for privacy focused tasks. Templates can be supported and updated without any programming or technical knowledge required. Output is generated in JSON, CSV, XML and custom format if required and you can use it to create custom template with C#.

Fast application programming interfaces of ByteScout Document Parser SDK for C# plus the instruction and the code below will help you quickly learn how to create custom template. Follow the instructions from the scratch to work and copy the C# code. Further enhancement of the code will make it more vigorous.

Free trial version of ByteScout Document Parser SDK is available for download from our website. Get it to try other source code samples for C#.

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>CustomTemplate</RootNamespace> <AssemblyName>CustomTemplate</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" /> <Compile Include="Properties\AssemblyInfo.cs" /> </ItemGroup> <ItemGroup> <Content Include="SampleInvoice.pdf"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> <Content Include="SampleTemplate.yml"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> </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 15 VisualStudioVersion = 15.0.27703.2018 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomTemplate", "CustomTemplate.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 data parsing from an invoice using the custom template. namespace CustomTemplate { class Program { static void Main(string[] args) { string customTemplate = @".\SampleTemplate.yml"; string inputDocument = @".\SampleInvoice.pdf"; // Create DocumentParser instance using (DocumentParser documentParser = new DocumentParser("demo", "demo")) { Console.WriteLine({code}quot;Loading template \"{customTemplate}\"..."); Console.WriteLine(); documentParser.AddTemplate(customTemplate); Console.WriteLine({code}quot;Parsing \"{inputDocument}\"..."); Console.WriteLine(); // Parse invoice data in JSON format string jsonString = documentParser.ParseDocument(inputDocument, OutputFormat.JSON); // Display parsed data in console Console.WriteLine("Parsing results 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

--- templateVersion: 1 sourceId: My Custom Template detectionRules: # Few regex expressions uniquely identifying the document design. # Don't forget to escape special characters. keywords: - Your Company Name - Invoice No\. - TOTAL # Expressions to extract distinct fields. # Last matching group or "<value>" group will be passed to result. fields: total: expression: TOTAL\s+(\d+\.\d+) type: decimal dateIssued: expression: Invoice Date (\d{2}/\d{2}/\d{4}) # If type is dateTime and dateFormat property is specified # the date will be converted to universal time by the specified format. type: dateTime dateFormat: MM/dd/yyyy invoiceId: expression: Invoice No. (\d+) # Static field that will be passed to result unchanged. sourceName: expression: Vendor Company static: true # Couple of fixed rectangular fields. # You can use "Template Editor" application to add them with ease. billTo: # Rectangle coordinates sequence: x, y, width, height. rect: - 32.25 - 150 - 348 - 70.5 notes: rect: - 32.25 - 227.25 - 531 - 47.25 # Optional page index parameter (zero-based) if you need to extract from specific page. pageIndex: 0 # Table data extraction. tables: - name: table1 start: # Table start after header row "Item Quantity Price Total". expression: Item\s+Quantity\s+Price\s+Total end: # Table rows last until "TOTAL" keyword. expression: TOTAL row: # Regex for table rows extraction. expression: ^\s*(?<description>\w+.*)(?<quantity>\d+)\s+(?<unitPrice>\d+\.\d{2})\s+(?<itemTotal>\d+\.\d{2})\s*$ types: # Column datatypes. Names correspond to regex matching groups. unitPrice: decimal itemTotal: decimal options: # multipage - set 'true' if table data can continue on following pages. multipage: false

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