How to convert PDF to XLSX from URL for PDF to excel API in PowerShell and PDF.co Web API

How to convert PDF to XLSX from URL for PDF to excel API in PowerShell: How To Tutorial

The documentation is designed to help you to implement the features on your side. PDF.co Web API helps with PDF to excel API in PowerShell. PDF.co Web API is the Rest API that provides set of data extraction functions, tools for documents manipulation, splitting and merging of pdf files. Includes built-in OCR, images recognition, can generate and read barcodes from images, scans 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. You can use these PowerShell sample examples in one or many applications.

PDF.co Web API – free trial version is on available our website. Also, there are other code samples to help you with your PowerShell application included into trial version.

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

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

ConvertPdfToXlsxFromUrl.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-excel/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 XLSX file name $DestinationFile = ".\result.xlsx" # Prepare URL for `PDF To XLSX` API call $query = "https://api.pdf.co/v1/pdf/convert/to/xlsx" # Prepare request body (will be auto-converted to JSON by Invoke-RestMethod) # See documentation: https://apidocs.pdf.co $body = @{ "name" = $(Split-Path $DestinationFile -Leaf) "password" = $Password "pages" = $Pages "url" = $SourceFileUrl } | ConvertTo-Json try { # Execute request $response = Invoke-WebRequest -Method Post -Headers @{ "x-api-key" = $API_KEY; "Content-Type" = "application/json" } -Body $body -Uri $query $jsonResponse = $response.Content | ConvertFrom-Json if ($jsonResponse.error -eq $false) { # Get URL of generated XLSX file $resultFileUrl = $jsonResponse.url; # Download XLSX file Invoke-WebRequest -Headers @{ "x-api-key" = $API_KEY } -OutFile $DestinationFile -Uri $resultFileUrl Write-Host "Generated XLSX file saved as `"$($DestinationFile)`" file." } 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 "& .\ConvertPdfToXlsxFromUrl.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: