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
      
--- # 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: 2 templatePriority: 0 sourceId: Multipage Table Test detectionRules: keywords: - Sample document with multi-page table fields: total: expression: TOTAL {{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

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit PDF.co Web API Home Page

Explore PDF.co Web API Documentation

Explore Samples

Sign Up for PDF.co Web API Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

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 }

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit PDF.co Web API Home Page

Explore PDF.co Web API Documentation

Explore Samples

Sign Up for PDF.co Web API Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

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

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit PDF.co Web API Home Page

Explore PDF.co Web API Documentation

Explore Samples

Sign Up for PDF.co Web API Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

VIDEO

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit PDF.co Web API Home Page

Explore PDF.co Web API Documentation

Explore Samples

Sign Up for PDF.co Web API Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Related Samples: