ByteScout Cloud API Server: API server that is ready to use and can be installed and deployed in less than 30 minutes on your own Windows server or server in a cloud. It can save data and files on your local server-based file storage or in Amazon AWS S3 storage. Data is processed solely on the API server and is powered by ByteScout engine, no cloud services or Internet connection is required for data processing..
On-demand (REST Web API) version:
Web API (on-demand version)
On-premise offline SDK for Windows:
60 Day Free Trial (on-premise)
---
# Template that demonstrates parsing of multi-page table using only
# regular expressions for the table start, end, and rows.
# If regular expression cannot be written for every table row (for example,
# if the table contains empty cells), try the second method demonstrated
# in `MultiPageTable-template2.yml` template.
templateVersion: 3
templatePriority: 0
sourceId: Multipage Table Test
detectionRules:
keywords:
- Sample document with multi-page table
fields:
total:
type: regex
expression: TOTAL {{DECIMAL}}
dataType: decimal
tables:
- name: table1
start:
# regular expression to find the table start in document
expression: Item\s+Description\s+Price\s+Qty\s+Extended Price
end:
# regular expression to find the table end in document
expression: TOTAL\s+\d+\.\d\d
row:
# regular expression to find table rows
expression: '^\s*(?<itemNo>\d+)\s+(?<description>.+?)\s+(?<price>\d+\.\d\d)\s+(?<qty>\d+)\s+(?<extPrice>\d+\.\d\d)'
columns:
- name: itemNo
type: integer
- name: description
type: string
- name: price
type: decimal
- name: qty
type: integer
- name: extPrice
type: decimal
multipage: true
# Please NOTE: In this sample we're assuming Cloud Api Server is hosted at "https://localhost".
# If it's not then please replace this with with your hosting url.
# Source PDF file
$SourceFile = ".\MultiPageTable.pdf"
# Destination JSON file name
$DestinationFile = ".\result.json"
# 1. RETRIEVE THE PRESIGNED URL TO UPLOAD THE FILE.
# * If you already have a direct file URL, skip to the step 3.
# Prepare URL for `Get Presigned URL` API call
$query = "https://localhost/file/upload/get-presigned-url?contenttype=application/octet-stream&name=" + `
[System.IO.Path]::GetFileName($SourceFile)
$query = [System.Uri]::EscapeUriString($query)
try {
# Execute request
$jsonResponse = Invoke-RestMethod -Method Get -Uri $query
if ($jsonResponse.error -eq $false) {
# Get URL to use for the file upload
$uploadUrl = $jsonResponse.presignedUrl
# Get URL of uploaded file to use with later API calls
$uploadedFileUrl = $jsonResponse.url
# 2. UPLOAD THE FILE TO CLOUD.
$r = Invoke-WebRequest -Method Put -Headers @{ "content-type" = "application/octet-stream" } -InFile $SourceFile -Uri $uploadUrl
if ($r.StatusCode -eq 200) {
# 3. Parse PDF document by template
# Template text. Use Document Parser SDK (https://bytescout.com/products/developer/documentparsersdk/index.html)
# to create templates.
# Read template from file:
$templateContent = [IO.File]::ReadAllText(".\MultiPageTable-template1.yml")
# Prepare URL for `Document Parser` API call
$query = "https://localhost/pdf/documentparser"
# Content
$Body = @{
"url" = $uploadedFileUrl;
"template" = $templateContent;
}
# Execute request
$jsonResponse = Invoke-RestMethod -Method 'Post' -Uri $query -Body ($Body|ConvertTo-Json) -ContentType "application/json"
if ($jsonResponse.error -eq $false) {
# Get URL of generated HTML file
$resultFileUrl = $jsonResponse.url;
# Download output file
Invoke-WebRequest -OutFile $DestinationFile -Uri $resultFileUrl
Write-Host "Generated output file saved as `"$($DestinationFile)`" file."
}
else {
# Display service reported error
Write-Host $jsonResponse.message
}
}
else {
# Display request error status
Write-Host $r.StatusCode + " " + $r.StatusDescription
}
}
else {
# Display service reported error
Write-Host $jsonResponse.message
}
}
catch {
# Display request error
Write-Host $_.Exception
}
@echo off
powershell -NoProfile -ExecutionPolicy Bypass -Command "& .\ParseFromUploadedFile.ps1"
echo Script finished with errorlevel=%errorlevel%
pause
See also:
Get Your API Key
See also: