Link Search Menu Expand Document

Create Custom Template - VB.NET

Document Parser SDK sample in VB.NET demonstrating ‘Create Custom Template’

Module1.vb
Imports ByteScout.DocumentParser

' This example demonstrates data parsing from an invoice using the custom template.

Module Module1

    Sub Main()

        Dim customTemplate As String = ".\SampleTemplate.yml"
        Dim inputDocument As String = ".\SampleInvoice.pdf"

        ' Create DocumentParser instance
        Using documentParser As New DocumentParser("demo", "demo")

            Console.WriteLine($"Loading template ""{customTemplate}""...")
            Console.WriteLine()

            documentParser.AddTemplate(customTemplate)

            Console.WriteLine($"Parsing ""{inputDocument}""...")
            Console.WriteLine()

            ' Parse invoice data in JSON format
            Dim jsonString As String = documentParser.ParseDocument(inputDocument, OutputFormat.JSON)
            ' Display parsed data in console
            Console.WriteLine("Parsing results in JSON format:")
            Console.WriteLine()
            Console.WriteLine(jsonString)
            
        End Using

        Console.WriteLine()
        Console.WriteLine("Press any key to continue...")
        Console.ReadLine()

    End Sub

End Module

SampleTemplate.yml
templateName: My Custom Template
templateVersion: 4
templatePriority: 0
detectionRules:
  keywords:
  - Your Company Name
  - Invoice No\.
  - TOTAL
objects:
- name: total
  objectType: field
  fieldProperties:
    fieldType: macros
    expression: TOTAL{{Spaces}}{{Number}}
    dataType: decimal
    pageIndex: 0
- name: dateIssued
  objectType: field
  fieldProperties:
    fieldType: macros
    expression: Invoice Date {{SmartDate}}
    dataType: date
    dateFormat: auto-mdy
    pageIndex: 0
- name: invoiceId
  objectType: field
  fieldProperties:
    fieldType: macros
    expression: Invoice No. {{Digits}}
    pageIndex: 0
- name: companyName
  objectType: field
  fieldProperties:
    fieldType: static
    expression: Vendor Company
    pageIndex: 0
- name: billTo
  objectType: field
  fieldProperties:
    fieldType: rectangle
    rectangle:
    - 32.25
    - 150
    - 348
    - 70.5
    pageIndex: 0
- name: notes
  objectType: field
  fieldProperties:
    fieldType: rectangle
    rectangle:
    - 32.25
    - 227.25
    - 531
    - 47.25
    pageIndex: 0
- name: table1
  objectType: table
  tableProperties:
    start:
      expression: Item\s+Quantity\s+Price\s+Total
      regex: true
    end:
      expression: TOTAL
      regex: true
    row:
      expression: ^\s*(?<description>\w+.*)(?<quantity>\d+)\s+(?<unitPrice>\d+\.\d{2})\s+(?<itemTotal>\d+\.\d{2})\s*$
      regex: true


Download Source Code (.zip)

Return to the previous page Explore Document Parser SDK


Copyright © 2016 - 2021 ByteScout