ByteScout Cloud API Server - PDF Classifier - PowerShell - Classify Uploaded PDF Asynchronously - ByteScout

ByteScout Cloud API Server – PDF Classifier – PowerShell – Classify Uploaded PDF Asynchronously

  • Home
  • /
  • Articles
  • /
  • ByteScout Cloud API Server – PDF Classifier – PowerShell – Classify Uploaded PDF Asynchronously

PDF classifier in PowerShell with ByteScout Cloud API Server

How to apply ByteScout Cloud API Server for PDF classifier in PowerShell

These source code samples are assembled by their programming language and functions they use. PDF classifier in PowerShell can be applied with ByteScout Cloud API Server. ByteScout Cloud API Server is the ready to use Web API Server that can be deployed in less than 30 minutes into your own in-house server or into private cloud server. Can store data on in-house local server based storage or in Amazon AWS S3 bucket. Processing data solely on the server using buil-in ByteScout powered engine, no cloud services are used to process your data!.

Want to speed up the application development? Then this PowerShell, code samples for PowerShell, developers help to speed up the application development and writing a code when using ByteScout Cloud API Server. If you want to know how it works, then this PowerShell sample code should be copied and pasted into your application’s code editor. Then just compile and run it. Enjoy writing a code with ready-to-use sample PowerShell codes to implement PDF classifier using ByteScout Cloud API Server.

Visit our website to get a free trial version of ByteScout Cloud API Server. Free trial contains many of source code samples to help you 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)

ClassifyPdfWithUploadAsync.ps1
      
$APIBaseURL='http://localhost:80' $scriptDir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent $InputFile = "$scriptDir\sample.pdf" $RulesSpreadsheet = "$scriptDir\rules.csv" $RulesColumnIndex = 1 $ResultIdentifiersColumnIndex = 0 function main() { $rules = Get-Content -Path $RulesSpreadsheet | Out-String Write-Host "Uploading document `"$InputFile`"" -ForegroundColor Green $fileUrl = UploadFile $InputFile if ($null -ne $fileUrl) { Write-Host "Processing document..." $result = ClassifyDocument $fileUrl $rules if ($null -ne $result) { Write-Host "Detected classes:" foreach ($elem in $result.classes) { Write-Host $elem.class } } } } function ClassifyDocument($fileUrl, $rules) { # Prepare URL for `pdf/classifier` API call $query = "$APIBaseURL/pdf/classifier" # Prepare POST request body $body = @{ "async" = "true"; "url" = $fileUrl; "rulesCsv" = $rules; "resultIdentifiersColumn" = $ResultIdentifiersColumnIndex; "rulesColumn" = $RulesColumnIndex; "caseSensitive" = $false } | ConvertTo-Json # Note, rules can also be passed as URL of file `rulesCsvUrl` param instead of `rulesCsv`. # Rules can be a spreadhset in CSV, XLS, XLSX, ODS format. try { # Execute request $jsonResponse = Invoke-RestMethod -Method Post -Uri $query -Body $body if ($jsonResponse.error -eq $false) { # Asynchronous job ID $jobId = $jsonResponse.jobId # URL of generated TXT file that will available after the job completion $resultFileUrl = $jsonResponse.url # Check the job status in a loop. do { $statusCheckUrl = "{0}/job/check?jobid={1}" -f $APIBaseURL, $jobId $jsonStatus = Invoke-RestMethod -Method Get -Uri $statusCheckUrl # Display timestamp and status (for demo purposes) Write-Host "$(Get-date): $($jsonStatus.status)" if ($jsonStatus.status -eq "success") { # Download result return Invoke-WebRequest -Uri $resultFileUrl | ConvertFrom-Json } elseif ($jsonStatus.status -eq "working") { # Pause for a few seconds Start-Sleep -Seconds 3 } else { Write-Host $jsonStatus.status break } } while ($true) } else { # Display service reported error Write-Host $jsonResponse.message } } catch { # Display exception if any Write-Host $_.Exception } return $null } function UploadFile($filePath) { # Prepare URL for `Get Presigned URL` API call $query = "{0}/file/upload/get-presigned-url?contenttype=application/octet-stream&name={1}" -f ` $APIBaseURL, [System.IO.Path]::GetFileName($filePath) $query = [System.Uri]::EscapeUriString($query) try { # Execute request $jsonResponse = Invoke-RestMethod -Method Get -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 # UPLOAD THE FILE $r = Invoke-WebRequest -Method Put -Headers @{ "content-type" = "application/octet-stream" } -InFile $filePath -Uri $uploadUrl if ($r.StatusCode -eq 200) { return $uploadedFileUrl } 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 } return $null; } main trap { Write-Host "Exception: $_" -ForegroundColor White -BackgroundColor DarkRed exit 1 }

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout Cloud API Server Home Page

Explore ByteScout Cloud API Server Documentation

Explore Samples

Sign Up for ByteScout Cloud API Server 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 "& .\ClassifyPdfWithUploadAsync.ps1" echo Script finished with errorlevel=%errorlevel% pause

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout Cloud API Server Home Page

Explore ByteScout Cloud API Server Documentation

Explore Samples

Sign Up for ByteScout Cloud API Server 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 ByteScout Cloud API Server Home Page

Explore ByteScout Cloud API Server Documentation

Explore Samples

Sign Up for ByteScout Cloud API Server Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Tutorials:

prev
next