How to convert PDF to XML from URL for PDF to XML API in PowerShell using PDF.co Web API

How to convert PDF to XML from URL for PDF to XML API in PowerShell: Step By Step Tutorial

We’ve created and updating regularly our sample code library so you may quickly learn PDF to XML API and the step-by-step process in PowerShell. PDF.co Web API was made to help with PDF to XML API in PowerShell. PDF.co Web API is the Web API with a set of tools for documents manipulation, data conversion, data extraction, splitting and merging of documents. Includes image recognition, built-in OCR, barcode generation and barcode decoders to decode bar codes from scans, pictures and pdf.

PowerShell code samples for PowerShell developers help to speed up the application’s code writing when using PDF.co Web API. This PowerShell sample code should be copied and pasted into your project. After doing this just compile your project and click Run. Enjoy writing a code with ready-to-use sample PowerShell codes to implement PDF to XML API using PDF.co Web API.

Our website provides free trial version of PDF.co Web API that includes source code samples to help with your PowerShell project.

Try PDF.co Web API today: Get 60 Day Free Trial or sign up for Web API

ConvertPdfToXmlFromUrl.ps1
      
# The authentication key (API Key). # Get your own by registering at https://app.pdf.co/documentation/api $API_KEY = "***********************************" # Direct URL of source PDF file. $SourceFileUrl = "https://bytescout-com.s3.amazonaws.com/files/demo-files/cloud-api/pdf-to-xml/sample.pdf" # Comma-separated list of page indices (or ranges) to process. Leave empty for all pages. Example: '0,2-5,7-'. $Pages = "" # PDF document password. Leave empty for unprotected documents. $Password = "" # Destination XML file name $DestinationFile = ".\result.xml" # Prepare URL for `PDF To XML` API call $query = "https://api.pdf.co/v1/pdf/convert/to/xml?name={0}&password={1}&pages={2}&url={3}" -f ` $(Split-Path $DestinationFile -Leaf), $Password, $Pages, $SourceFileUrl $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 of generated XML file $resultFileUrl = $jsonResponse.url; # Download XML file Invoke-WebRequest -Headers @{ "x-api-key" = $API_KEY } -OutFile $DestinationFile -Uri $resultFileUrl Write-Host "Generated XML file saved as `"$($DestinationFile)`" file." } else { # Display service reported error Write-Host $jsonResponse.message } } catch { # Display request error Write-Host $_.Exception }

Try PDF.co Web API today: 60 Day Free Trial (on-premise version) or sign up for Web API (on demand version)

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

Try PDF.co Web API today: 60 Day Free Trial (on-premise version) or sign up for Web API (on demand version)

VIDEO

ON-PREMISE VERSION

Get 60 Day Free Trial or Visit PDF.co Web API page

Explore PDF.co Web API documentation

WEB API

Sign Up for free Web API key

Explore Web API Documentation

Related Samples: