Parse Simple Document - VBScript and VB6
Document Parser SDK sample in VBScript and VB6 demonstrating ‘Parse Simple Document’
AmazonAWS.yml
templateName: Amazon Web Services Invoice
templateVersion: 4
templatePriority: 0
detectionRules:
keywords:
- Amazon Web Services
- ATTN
- Invoice
objects:
- name: total
objectType: field
fieldProperties:
fieldType: macros
expression: TOTAL AMOUNT DUE ON{{Anything}}{{Dollar}}({{Number}})
regex: true
dataType: decimal
- name: subTotal
objectType: field
fieldProperties:
fieldType: macros
expression: '{{LineStart}}{{Spaces}}Charges{{Spaces}}{{Dollar}}({{Number}})'
regex: true
dataType: decimal
- name: dateIssued
objectType: field
fieldProperties:
fieldType: macros
expression: Invoice Date:{{Spaces}}({{Anything}}){{LineEnd}}
regex: true
dataType: date
dateFormat: MMMM d , yyyy
- name: invoiceId
objectType: field
fieldProperties:
fieldType: macros
expression: Invoice Number:{{Spaces}}({{Digits}})
regex: true
- name: companyName
objectType: field
fieldProperties:
fieldType: static
expression: Amazon Web Services, Inc.
regex: true
- name: companyWebsite
objectType: field
fieldProperties:
fieldType: static
expression: aws.amazon.com
regex: true
- name: billTo
objectType: field
fieldProperties:
fieldType: rectangle
expression: Bill to Address:{{ToggleSingleLineMode}}({{AnythingGreedy}})
regex: true
rectangle:
- 33
- 115.5
- 213.75
- 72.75
pageIndex: 0
- name: currency
objectType: field
fieldProperties:
fieldType: static
expression: USD
regex: true
- name: table1
objectType: table
tableProperties:
start:
expression: '{{LineStart}}{{Spaces}}Detail{{LineEnd}}'
regex: true
end:
expression: '{{EndOfPage}}'
regex: true
row:
expression: '{{LineStart}}{{Spaces}}(?<description>{{SentenceWithSingleSpaces}}){{Spaces}}{{Dollar}}(?<unitPrice>{{Number}}){{LineEnd}}'
regex: true
columns:
- name: unitPrice
dataType: decimal
DigitalOcean.yml
templateName: DigitalOcean Invoice
templateVersion: 4
templatePriority: 0
detectionRules:
keywords:
- DigitalOcean
- 101 Avenue of the Americas
- Invoice Number
objects:
- name: companyName
objectType: field
fieldProperties:
fieldType: static
expression: DigitalOcean
regex: true
- name: invoiceId
objectType: field
fieldProperties:
fieldType: macros
expression: 'Invoice Number: ({{Digits}})'
regex: true
- name: dateIssued
objectType: field
fieldProperties:
fieldType: macros
expression: 'Date Issued: ({{SmartDate}})'
regex: true
dataType: date
dateFormat: auto-mdy
- name: total
objectType: field
fieldProperties:
fieldType: macros
expression: 'Total: {{Dollar}}({{Number}})'
regex: true
dataType: decimal
- name: currency
objectType: field
fieldProperties:
fieldType: static
expression: USD
regex: true
- name: table1
objectType: table
tableProperties:
start:
expression: Description{{Spaces}}Hours
regex: true
end:
expression: 'Total:'
regex: true
row:
expression: '{{LineStart}}{{Spaces}}(?<description>{{SentenceWithSingleSpaces}}){{Spaces}}(?<hours>{{Digits}}){{Spaces}}(?<start>{{2Digits}}{{Minus}}{{2Digits}}{{Space}}{{2Digits}}{{Colon}}{{2Digits}}){{Spaces}}(?<end>{{2Digits}}{{Minus}}{{2Digits}}{{Space}}{{2Digits}}{{Colon}}{{2Digits}}){{Spaces}}{{Dollar}}(?<unitPrice>{{Number}})'
regex: true
columns:
- name: hours
dataType: integer
- name: unitPrice
dataType: decimal
GeneralExample.vbs
' This example demonstrates document data parsing to JSON and YAML formats.
template1 = ".\DigitalOcean.yml"
template2 = ".\AmazonAWS.yml"
inputDocument1 = ".\DigitalOcean.pdf"
inputDocument2 = ".\AmazonAWS.pdf"
' Create DocumentParser object
Set documentParser = CreateObject("Bytescout.DocumentParser.DocumentParser")
documentParser.RegistrationName = "demo"
documentParser.RegistrationKey = "demo"
' Create ComHelpers object
Set comHelpers = CreateObject("Bytescout.DocumentParser.ComHelpers")
' Loading templates...
documentParser.AddTemplate(template1)
documentParser.AddTemplate(template2)
' Parse document data in JSON format
documentParser.ParseDocument inputDocument1, "output1.json", comHelpers.OUTPUTFORMAT_JSON
' Parse document data in YAML format
documentParser.ParseDocument inputDocument2, "output2.yaml", comHelpers.OUTPUTFORMAT_YAML
' Parse document data in CSV format
Set csvOptions = CreateObject("Bytescout.DocumentParser.CSVOptions")
csvOptions.GenerateColumnHeaders = True
csvOptions.SeparatorCharacter = ","
csvOptions.QuotationCharacter = """"
csvOptions.EncodingName = "utf-8"
documentParser.ParseDocument inputDocument1, "output3.csv", comHelpers.OUTPUTFORMAT_CSV, (csvOptions)
WScript.Echo "Parsed data saved as 'output1.json', 'output2.yaml', and 'output3.csv'."
Set documentParser = Nothing