Cloud API - PDF To Excel - PowerShell - Convert PDF To XLSX From URL - ByteScout

Cloud API – PDF To Excel – PowerShell – Convert PDF To XLSX From URL

  • Home
  • /
  • Articles
  • /
  • Cloud API – PDF To Excel – PowerShell – Convert PDF To XLSX From URL

Cloud API – PDF To Excel – PowerShell – Convert PDF To XLSX From URL

Whether you are a veteran or rookie web or software developer, you could benefit a lot from our lineup of Software Development Kits (SDKs). One, of which is Cloud API, a multi-tooled REST API that could simplify the coding process of converting PDF to Excel from URL in PowerShell for you.

Cloud API can also lighten your load on several areas of the development process such as data extraction, document formatting or editing, and merging or splitting PDFs. It can also be utilized to generate and read barcodes from PDFs, image files, and scanned documents such as invoices, receipts, etc. It has a built-in OCR and an image recognition capability, as well.

If you are interested in finding out how it can help you in converting PDF to Excel API in PowerShell, just copy and paste the sample code that we provided into your coding project. The process wouldn’t take much time and energy on your part. You may also opt to get this PowerShell code snippet from our GitHub.

Download the FREE ByteScout trial version from our website so you can appreciate better what our SDK can do for you. Programming tutorials are also afforded together with the sample source code samples.

ConvertPdfToXlsxFromUrl.ps1

# (!) If you are getting '(403) Forbidden' error please ensure you have set the correct API_KEY

# The authentication key (API Key).
# Get your own by registering at https://secure.bytescout.com/users/sign_up
$API_KEY = "***********************************"

# Direct URL of source PDF file.
$SourceFileUrl = "https://s3-us-west-2.amazonaws.com/bytescout-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?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 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

  Click here to get your Free Trial version of the SDK

Tutorials:

prev
next