How to parse from uploaded file for document parser API in Powershell using PDF.co Web API

Learn to write code parse from uploaded file for document parser API in Powershell: Simple How To Tutorial

The easy to understand coding guides help you check the features without any need to write your own code. PDF.co Web API helps with document parser API in Powershell. PDF.co Web API is the flexible Web API that includes full set of functions from e-signature requests to data extraction, OCR, images recognition, pdf splitting and pdf splitting. Can also generate barcodes and read barcodes from images, scans and pdf.

This simple and easy to understand sample source code in Powershell for PDF.co Web API contains different functions and options you should do calling the API to implement document parser API. This Powershell sample code can be used by copying and pasting into your project. Once done,just compile your project and click Run. Easy to understand tutorials are available along with installed PDF.co Web API if you’d like to learn more about the topic and the details of the API.

Our website provides free trial version of PDF.co Web API that gives source code samples to assist with your Powershell project.

On-demand (REST Web API) version:
 Web API (on-demand version)

On-premise offline SDK for Windows:
 60 Day Free Trial (on-premise)

MultiPageTable-template1.yml

      
templateName: Multipage Table Test templateVersion: 4 templatePriority: 0 detectionRules: keywords: - Sample document with multi-page table objects: - name: total objectType: field fieldProperties: fieldType: macros expression: TOTAL{{Spaces}}({{Number}}) regex: true dataType: decimal - name: table1 objectType: table tableProperties: start: expression: Item{{Spaces}}Description{{Spaces}}Price regex: true end: expression: TOTAL{{Spaces}}{{Number}} regex: true row: expression: '{{LineStart}}{{Spaces}}(?<itemNo>{{Digits}}){{Spaces}}(?<description>{{SentenceWithSingleSpaces}}){{Spaces}}(?<price>{{Number}}){{Spaces}}(?<qty>{{Digits}}){{Spaces}}(?<extPrice>{{Number}})' regex: true columns: - name: itemNo dataType: integer - name: description dataType: string - name: price dataType: decimal - name: qty dataType: integer - name: extPrice dataType: decimal multipage: true

ParseFromUploadedFile.ps1

      
# The authentication key (API Key). # Get your own by registering at https://app.pdf.co/documentation/api $API_KEY = "***********************************" # 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://api.pdf.co/v1/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 -Headers @{ "x-api-key" = $API_KEY } -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 @{ "x-api-key" = $API_KEY; "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://api.pdf.co/v1/pdf/documentparser" # Content $Body = @{ "url" = $uploadedFileUrl; "template" = $templateContent; } # Execute request $jsonResponse = Invoke-RestMethod -Method 'Post' -Headers @{ "x-api-key" = $API_KEY } -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 -Headers @{ "x-api-key" = $API_KEY } -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 }

run.bat

      
@echo off powershell -NoProfile -ExecutionPolicy Bypass -Command "& .\ParseFromUploadedFile.ps1" echo Script finished with errorlevel=%errorlevel% pause

VIDEO

ON-PREMISE OFFLINE SDK

Get 60 Day Free Trial

See also:

ON-DEMAND REST WEB API

Get Your API Key

See also:

Related Samples: