Create Custom Template - VBScript and VB6
Document Parser SDK sample in VBScript and VB6 demonstrating ‘Create Custom Template’
CustomTemplate.vbs
' This example demonstrates data parsing from an invoice using the custom template.
customTemplate = ".\SampleTemplate.yml"
inputDocument = ".\SampleInvoice.pdf"
' Create DocumentParser object
Set documentParser = CreateObject("Bytescout.DocumentParser.DocumentParser")
documentParser.RegistrationName = "demo"
documentParser.RegistrationKey = "demo"
' Load custom template
documentParser.AddTemplate customTemplate
' Parse invoice data in JSON format
documentParser.ParseDocument inputDocument, "output1.json", 0 ' 0 = OutputFormat.JSON
WScript.Echo "Parsed data saved as 'output1.json'."
Set documentParser = Nothing
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