These examples demonstrate common PDF to Image API workflows via HTTP API.
You can run the examples below with the displayed API credentials. Update the input URLs and filenames as needed.
Use a Bash-compatible shell.
Basic options
-u — Supply your username and API key.-F — Send a form field.-o — Save the response to a file.-f — Report HTTP errors as command failures.-s -S — Hide the progress meter while keeping error messages.File input
file=@document.pdf — Upload a local file.Diagnostics
--fail-with-body
— Use instead of -f to retain the error response body.
-D — Save response headers to a file.-w — Print response information;
the diagnostic example
prints the HTTP status.
Install Requests with
python3 -m pip install requests. Save an example as
convert.py and run it with python3 convert.py.
Request options
auth — Supply your username and API key using HTTP Basic authentication.data — Send form fields; Requests encodes their values.files — Upload files opened in binary mode. Requests sets the multipart boundary.allow_redirects=False — Return the endpoint's response without following redirects.Response handling
raise_for_status() — Raise an exception for HTTP errors before opening the output file.response.content — Save the response bytes to a file opened with "wb".with — Close opened files even if the request or output write fails.
Connection errors raise exceptions. The examples do not set a client timeout or
retry requests. If you add a timeout, allow for conversion time;
Requests applies connection and read timeouts, not an overall conversion deadline.
The diagnostic example
saves response headers and body and prints the HTTP status before calling
raise_for_status(), so an HTTP error still leaves diagnostic files.
Use Node.js with its built-in Fetch API; no HTTP package is needed.
Save an example as convert.mjs and run it with
node convert.mjs. The .mjs extension enables imports
and top-level await.
Request options
Authorization — Send your username and API key using HTTP Basic authentication.FormData — Send form fields and files. Fetch sets the multipart boundary.readFile and Blob — Read uploads as bytes into memory and include their filenames.redirect: 'manual' — Return the endpoint's response without following redirects.Response handling
response.arrayBuffer() — Read the response bytes into memory.response.status — Check for HTTP errors before opening the output file; Fetch does not throw for HTTP errors itself.writeFile — Save the bytes to the output file. File and connection errors propagate as exceptions.
The examples use Fetch's native connection, response-header, and body inactivity
limits, which depend on the Node.js runtime. They do not set an overall conversion
deadline or retry requests. Allow for conversion time if you add a timeout using
an AbortSignal.
The diagnostic example saves response headers and body and prints the HTTP status before throwing on an HTTP error, so diagnostic files remain available.
Install Axios with npm install axios. Save an example as
convert.mjs and run it with node convert.mjs.
The .mjs extension enables imports and top-level await.
Request options
auth — Send your username and API key using HTTP Basic authentication.FormData — Send form fields and files. Axios sets the multipart boundary.readFile and Blob — Read uploads as bytes into memory and include their filenames.maxRedirects: 0 — Return the endpoint's response without following redirects.Response handling
responseType: 'arraybuffer' — Read the response as bytes.validateStatus — Reject HTTP errors before writing the output file.writeFile — Save the response bytes to the output file.Axios does not set an overall timeout by default. Allow for conversion time if you add one. Failed requests and file writes produce an error message and a nonzero exit status; the error handler prints only the message so request credentials are not included.
The diagnostic example saves response headers and body and prints the HTTP status before reporting an HTTP error, so diagnostic files remain available.
Install Guzzle with composer require guzzlehttp/guzzle.
Save an example as convert.php beside your vendor
directory and run it with php convert.php.
Request options
auth — Send your username and API key using HTTP Basic authentication.multipart — Send form fields and files. Guzzle sets the multipart boundary.Utils::tryFopen — Open input files as binary streams for upload.'allow_redirects' => false — Return the endpoint's response without following redirects.Response handling
'http_errors' => false — Inspect the HTTP status before writing the output file.getBody — Read the response as a binary string.file_put_contents — Save the response bytes and check that the entire result was written.Guzzle does not set an overall timeout by default. Allow for conversion time if you add one. Failed requests and file writes produce an error message and a nonzero exit status.
The diagnostic example saves response headers and body and prints the HTTP status before reporting an HTTP error, so diagnostic files remain available.
Upload invoice.pdf and save its PNG page images in invoice.zip.
curl -f -s -S \ -u 'demo:demo' \ -o invoice.zip \ -F file=@invoice.pdf \ -F input_format=pdf \ -F output_format=png \ -F force_zip=true \ https://api.pdfcrowd.com/convert/24.04/
import requests with open('invoice.pdf', 'rb') as input_1: response = requests.post( 'https://api.pdfcrowd.com/convert/24.04/', auth=('demo', 'demo'), data={ 'input_format': 'pdf', 'output_format': 'png', 'force_zip': 'true', }, files={ 'file': input_1, }, allow_redirects=False, ) response.raise_for_status() with open('invoice.zip', 'wb') as output_file: output_file.write(response.content)
import { readFile, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "pdf"); form.append("output_format", "png"); form.append("force_zip", "true"); form.append("file", new Blob([await readFile("invoice.pdf")]), basename("invoice.pdf")); const response = await fetch("https://api.pdfcrowd.com/convert/24.04/", { method: 'POST', headers: { Authorization: 'Basic ' + Buffer.from( username + ':' + apiKey).toString('base64'), }, body: form, redirect: 'manual', }); const body = Buffer.from(await response.arrayBuffer()); if (response.status >= 400) { throw new Error('HTTP ' + response.status + ' ' + response.statusText); } await writeFile("invoice.zip", body);
import axios from 'axios'; import { readFile, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "pdf"); form.append("output_format", "png"); form.append("force_zip", "true"); form.append("file", new Blob([await readFile("invoice.pdf")]), basename("invoice.pdf")); try { const response = await axios.post("https://api.pdfcrowd.com/convert/24.04/", form, { auth: { username, password: apiKey }, responseType: 'arraybuffer', maxRedirects: 0, validateStatus: status => status < 400, }); await writeFile("invoice.zip", response.data); } catch (error) { console.error(error.message); process.exitCode = 1; }
<?php require 'vendor/autoload.php'; use GuzzleHttp\Client; use GuzzleHttp\Psr7\Utils; try { $client = new Client(); $response = $client->post('https://api.pdfcrowd.com/convert/24.04/', [ 'auth' => ['demo', 'demo'], 'multipart' => [ ['name' => 'input_format', 'contents' => 'pdf'], ['name' => 'output_format', 'contents' => 'png'], ['name' => 'force_zip', 'contents' => 'true'], ['name' => 'file', 'contents' => Utils::tryFopen('invoice.pdf', 'rb'), 'filename' => basename('invoice.pdf')], ], 'allow_redirects' => false, 'http_errors' => false, ]); $status = $response->getStatusCode(); if ($status >= 400) { throw new \RuntimeException("HTTP $status " . $response->getReasonPhrase()); } $body = (string) $response->getBody(); if (file_put_contents('invoice.zip', $body) !== strlen($body)) { throw new \RuntimeException('Failed to write output file'); } } catch (\Throwable $error) { fwrite(STDERR, $error->getMessage() . "\n"); exit(1); }
Fetch the PDF from its URL and save its PNG page images in invoice.zip.
curl -f -s -S \ -u 'demo:demo' \ -o invoice.zip \ -F url=https://your-server.com/invoice.pdf \ -F input_format=pdf \ -F output_format=png \ -F force_zip=true \ https://api.pdfcrowd.com/convert/24.04/
import requests response = requests.post( 'https://api.pdfcrowd.com/convert/24.04/', auth=('demo', 'demo'), data={ 'input_format': 'pdf', 'output_format': 'png', 'force_zip': 'true', 'url': 'https://your-server.com/invoice.pdf', }, allow_redirects=False, ) response.raise_for_status() with open('invoice.zip', 'wb') as output_file: output_file.write(response.content)
import { writeFile } from 'node:fs/promises'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "pdf"); form.append("output_format", "png"); form.append("force_zip", "true"); form.append("url", "https://your-server.com/invoice.pdf"); const response = await fetch("https://api.pdfcrowd.com/convert/24.04/", { method: 'POST', headers: { Authorization: 'Basic ' + Buffer.from( username + ':' + apiKey).toString('base64'), }, body: form, redirect: 'manual', }); const body = Buffer.from(await response.arrayBuffer()); if (response.status >= 400) { throw new Error('HTTP ' + response.status + ' ' + response.statusText); } await writeFile("invoice.zip", body);
import axios from 'axios'; import { writeFile } from 'node:fs/promises'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "pdf"); form.append("output_format", "png"); form.append("force_zip", "true"); form.append("url", "https://your-server.com/invoice.pdf"); try { const response = await axios.post("https://api.pdfcrowd.com/convert/24.04/", form, { auth: { username, password: apiKey }, responseType: 'arraybuffer', maxRedirects: 0, validateStatus: status => status < 400, }); await writeFile("invoice.zip", response.data); } catch (error) { console.error(error.message); process.exitCode = 1; }
<?php require 'vendor/autoload.php'; use GuzzleHttp\Client; use GuzzleHttp\Psr7\Utils; try { $client = new Client(); $response = $client->post('https://api.pdfcrowd.com/convert/24.04/', [ 'auth' => ['demo', 'demo'], 'multipart' => [ ['name' => 'input_format', 'contents' => 'pdf'], ['name' => 'output_format', 'contents' => 'png'], ['name' => 'force_zip', 'contents' => 'true'], ['name' => 'url', 'contents' => 'https://your-server.com/invoice.pdf'], ], 'allow_redirects' => false, 'http_errors' => false, ]); $status = $response->getStatusCode(); if ($status >= 400) { throw new \RuntimeException("HTTP $status " . $response->getReasonPhrase()); } $body = (string) $response->getBody(); if (file_put_contents('invoice.zip', $body) !== strlen($body)) { throw new \RuntimeException('Failed to write output file'); } } catch (\Throwable $error) { fwrite(STDERR, $error->getMessage() . "\n"); exit(1); }
These examples use report.pdf, a three-page document with text, a chart, and vector graphics. The CropBox variant uses cropbox.pdf, a page with a predefined crop boundary.
Render page 1 of report.pdf directly as a PNG. Use 72 DPI for a compact preview or 300 DPI for more detail at higher pixel dimensions and file size. Selecting one page produces an image file without ZIP packaging.
Compact preview at 72 DPI:
curl -f -s -S \ -u 'demo:demo' \ -o preview.png \ -F file=@report.pdf \ -F input_format=pdf \ -F output_format=png \ -F dpi=72 \ -F print_page_range=1 \ https://api.pdfcrowd.com/convert/24.04/
import requests with open('report.pdf', 'rb') as input_1: response = requests.post( 'https://api.pdfcrowd.com/convert/24.04/', auth=('demo', 'demo'), data={ 'input_format': 'pdf', 'output_format': 'png', 'dpi': '72', 'print_page_range': '1', }, files={ 'file': input_1, }, allow_redirects=False, ) response.raise_for_status() with open('preview.png', 'wb') as output_file: output_file.write(response.content)
import { readFile, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "pdf"); form.append("output_format", "png"); form.append("dpi", "72"); form.append("print_page_range", "1"); form.append("file", new Blob([await readFile("report.pdf")]), basename("report.pdf")); const response = await fetch("https://api.pdfcrowd.com/convert/24.04/", { method: 'POST', headers: { Authorization: 'Basic ' + Buffer.from( username + ':' + apiKey).toString('base64'), }, body: form, redirect: 'manual', }); const body = Buffer.from(await response.arrayBuffer()); if (response.status >= 400) { throw new Error('HTTP ' + response.status + ' ' + response.statusText); } await writeFile("preview.png", body);
import axios from 'axios'; import { readFile, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "pdf"); form.append("output_format", "png"); form.append("dpi", "72"); form.append("print_page_range", "1"); form.append("file", new Blob([await readFile("report.pdf")]), basename("report.pdf")); try { const response = await axios.post("https://api.pdfcrowd.com/convert/24.04/", form, { auth: { username, password: apiKey }, responseType: 'arraybuffer', maxRedirects: 0, validateStatus: status => status < 400, }); await writeFile("preview.png", response.data); } catch (error) { console.error(error.message); process.exitCode = 1; }
<?php require 'vendor/autoload.php'; use GuzzleHttp\Client; use GuzzleHttp\Psr7\Utils; try { $client = new Client(); $response = $client->post('https://api.pdfcrowd.com/convert/24.04/', [ 'auth' => ['demo', 'demo'], 'multipart' => [ ['name' => 'input_format', 'contents' => 'pdf'], ['name' => 'output_format', 'contents' => 'png'], ['name' => 'dpi', 'contents' => '72'], ['name' => 'print_page_range', 'contents' => '1'], ['name' => 'file', 'contents' => Utils::tryFopen('report.pdf', 'rb'), 'filename' => basename('report.pdf')], ], 'allow_redirects' => false, 'http_errors' => false, ]); $status = $response->getStatusCode(); if ($status >= 400) { throw new \RuntimeException("HTTP $status " . $response->getReasonPhrase()); } $body = (string) $response->getBody(); if (file_put_contents('preview.png', $body) !== strlen($body)) { throw new \RuntimeException('Failed to write output file'); } } catch (\Throwable $error) { fwrite(STDERR, $error->getMessage() . "\n"); exit(1); }
High-resolution image at 300 DPI:
curl -f -s -S \ -u 'demo:demo' \ -o page-300dpi.png \ -F file=@report.pdf \ -F input_format=pdf \ -F output_format=png \ -F dpi=300 \ -F print_page_range=1 \ https://api.pdfcrowd.com/convert/24.04/
import requests with open('report.pdf', 'rb') as input_1: response = requests.post( 'https://api.pdfcrowd.com/convert/24.04/', auth=('demo', 'demo'), data={ 'input_format': 'pdf', 'output_format': 'png', 'dpi': '300', 'print_page_range': '1', }, files={ 'file': input_1, }, allow_redirects=False, ) response.raise_for_status() with open('page-300dpi.png', 'wb') as output_file: output_file.write(response.content)
import { readFile, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "pdf"); form.append("output_format", "png"); form.append("dpi", "300"); form.append("print_page_range", "1"); form.append("file", new Blob([await readFile("report.pdf")]), basename("report.pdf")); const response = await fetch("https://api.pdfcrowd.com/convert/24.04/", { method: 'POST', headers: { Authorization: 'Basic ' + Buffer.from( username + ':' + apiKey).toString('base64'), }, body: form, redirect: 'manual', }); const body = Buffer.from(await response.arrayBuffer()); if (response.status >= 400) { throw new Error('HTTP ' + response.status + ' ' + response.statusText); } await writeFile("page-300dpi.png", body);
import axios from 'axios'; import { readFile, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "pdf"); form.append("output_format", "png"); form.append("dpi", "300"); form.append("print_page_range", "1"); form.append("file", new Blob([await readFile("report.pdf")]), basename("report.pdf")); try { const response = await axios.post("https://api.pdfcrowd.com/convert/24.04/", form, { auth: { username, password: apiKey }, responseType: 'arraybuffer', maxRedirects: 0, validateStatus: status => status < 400, }); await writeFile("page-300dpi.png", response.data); } catch (error) { console.error(error.message); process.exitCode = 1; }
<?php require 'vendor/autoload.php'; use GuzzleHttp\Client; use GuzzleHttp\Psr7\Utils; try { $client = new Client(); $response = $client->post('https://api.pdfcrowd.com/convert/24.04/', [ 'auth' => ['demo', 'demo'], 'multipart' => [ ['name' => 'input_format', 'contents' => 'pdf'], ['name' => 'output_format', 'contents' => 'png'], ['name' => 'dpi', 'contents' => '300'], ['name' => 'print_page_range', 'contents' => '1'], ['name' => 'file', 'contents' => Utils::tryFopen('report.pdf', 'rb'), 'filename' => basename('report.pdf')], ], 'allow_redirects' => false, 'http_errors' => false, ]); $status = $response->getStatusCode(); if ($status >= 400) { throw new \RuntimeException("HTTP $status " . $response->getReasonPhrase()); } $body = (string) $response->getBody(); if (file_put_contents('page-300dpi.png', $body) !== strlen($body)) { throw new \RuntimeException('Failed to write output file'); } } catch (\Throwable $error) { fwrite(STDERR, $error->getMessage() . "\n"); exit(1); }
Render pages 1 and 3 of report.pdf as PNG images in selected-pages.zip. Force ZIP packaging so the result stays an archive even if you later select just one page.
curl -f -s -S \ -u 'demo:demo' \ -o selected-pages.zip \ -F file=@report.pdf \ -F input_format=pdf \ -F output_format=png \ -F force_zip=true \ -F print_page_range=1,3 \ https://api.pdfcrowd.com/convert/24.04/
import requests with open('report.pdf', 'rb') as input_1: response = requests.post( 'https://api.pdfcrowd.com/convert/24.04/', auth=('demo', 'demo'), data={ 'input_format': 'pdf', 'output_format': 'png', 'force_zip': 'true', 'print_page_range': '1,3', }, files={ 'file': input_1, }, allow_redirects=False, ) response.raise_for_status() with open('selected-pages.zip', 'wb') as output_file: output_file.write(response.content)
import { readFile, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "pdf"); form.append("output_format", "png"); form.append("force_zip", "true"); form.append("print_page_range", "1,3"); form.append("file", new Blob([await readFile("report.pdf")]), basename("report.pdf")); const response = await fetch("https://api.pdfcrowd.com/convert/24.04/", { method: 'POST', headers: { Authorization: 'Basic ' + Buffer.from( username + ':' + apiKey).toString('base64'), }, body: form, redirect: 'manual', }); const body = Buffer.from(await response.arrayBuffer()); if (response.status >= 400) { throw new Error('HTTP ' + response.status + ' ' + response.statusText); } await writeFile("selected-pages.zip", body);
import axios from 'axios'; import { readFile, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "pdf"); form.append("output_format", "png"); form.append("force_zip", "true"); form.append("print_page_range", "1,3"); form.append("file", new Blob([await readFile("report.pdf")]), basename("report.pdf")); try { const response = await axios.post("https://api.pdfcrowd.com/convert/24.04/", form, { auth: { username, password: apiKey }, responseType: 'arraybuffer', maxRedirects: 0, validateStatus: status => status < 400, }); await writeFile("selected-pages.zip", response.data); } catch (error) { console.error(error.message); process.exitCode = 1; }
<?php require 'vendor/autoload.php'; use GuzzleHttp\Client; use GuzzleHttp\Psr7\Utils; try { $client = new Client(); $response = $client->post('https://api.pdfcrowd.com/convert/24.04/', [ 'auth' => ['demo', 'demo'], 'multipart' => [ ['name' => 'input_format', 'contents' => 'pdf'], ['name' => 'output_format', 'contents' => 'png'], ['name' => 'force_zip', 'contents' => 'true'], ['name' => 'print_page_range', 'contents' => '1,3'], ['name' => 'file', 'contents' => Utils::tryFopen('report.pdf', 'rb'), 'filename' => basename('report.pdf')], ], 'allow_redirects' => false, 'http_errors' => false, ]); $status = $response->getStatusCode(); if ($status >= 400) { throw new \RuntimeException("HTTP $status " . $response->getReasonPhrase()); } $body = (string) $response->getBody(); if (file_put_contents('selected-pages.zip', $body) !== strlen($body)) { throw new \RuntimeException('Failed to write output file'); } } catch (\Throwable $error) { fwrite(STDERR, $error->getMessage() . "\n"); exit(1); }
Convert page 1 of report.pdf into page.jpg for applications that need JPEG input. JPEG is lossy and is not always smaller than PNG, especially for pages dominated by text and flat graphics.
curl -f -s -S \ -u 'demo:demo' \ -o page.jpg \ -F file=@report.pdf \ -F input_format=pdf \ -F output_format=jpg \ -F print_page_range=1 \ https://api.pdfcrowd.com/convert/24.04/
import requests with open('report.pdf', 'rb') as input_1: response = requests.post( 'https://api.pdfcrowd.com/convert/24.04/', auth=('demo', 'demo'), data={ 'input_format': 'pdf', 'output_format': 'jpg', 'print_page_range': '1', }, files={ 'file': input_1, }, allow_redirects=False, ) response.raise_for_status() with open('page.jpg', 'wb') as output_file: output_file.write(response.content)
import { readFile, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "pdf"); form.append("output_format", "jpg"); form.append("print_page_range", "1"); form.append("file", new Blob([await readFile("report.pdf")]), basename("report.pdf")); const response = await fetch("https://api.pdfcrowd.com/convert/24.04/", { method: 'POST', headers: { Authorization: 'Basic ' + Buffer.from( username + ':' + apiKey).toString('base64'), }, body: form, redirect: 'manual', }); const body = Buffer.from(await response.arrayBuffer()); if (response.status >= 400) { throw new Error('HTTP ' + response.status + ' ' + response.statusText); } await writeFile("page.jpg", body);
import axios from 'axios'; import { readFile, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "pdf"); form.append("output_format", "jpg"); form.append("print_page_range", "1"); form.append("file", new Blob([await readFile("report.pdf")]), basename("report.pdf")); try { const response = await axios.post("https://api.pdfcrowd.com/convert/24.04/", form, { auth: { username, password: apiKey }, responseType: 'arraybuffer', maxRedirects: 0, validateStatus: status => status < 400, }); await writeFile("page.jpg", response.data); } catch (error) { console.error(error.message); process.exitCode = 1; }
<?php require 'vendor/autoload.php'; use GuzzleHttp\Client; use GuzzleHttp\Psr7\Utils; try { $client = new Client(); $response = $client->post('https://api.pdfcrowd.com/convert/24.04/', [ 'auth' => ['demo', 'demo'], 'multipart' => [ ['name' => 'input_format', 'contents' => 'pdf'], ['name' => 'output_format', 'contents' => 'jpg'], ['name' => 'print_page_range', 'contents' => '1'], ['name' => 'file', 'contents' => Utils::tryFopen('report.pdf', 'rb'), 'filename' => basename('report.pdf')], ], 'allow_redirects' => false, 'http_errors' => false, ]); $status = $response->getStatusCode(); if ($status >= 400) { throw new \RuntimeException("HTTP $status " . $response->getReasonPhrase()); } $body = (string) $response->getBody(); if (file_put_contents('page.jpg', $body) !== strlen($body)) { throw new \RuntimeException('Failed to write output file'); } } catch (\Throwable $error) { fwrite(STDERR, $error->getMessage() . "\n"); exit(1); }
Extract the chart from page 1 of report.pdf into chart.png, or honor the predefined CropBox in cropbox.pdf to remove its production margins.
The chart example fixes 144 DPI and uses pixel coordinates from the rendered page's top-left corner: X = 96, Y = 370, width = 1024, height = 384. Adjust the coordinates when changing the page layout or DPI. The CropBox variant uses the boundary already stored in the PDF.
Extract a chart region:
curl -f -s -S \ -u 'demo:demo' \ -o chart.png \ -F file=@report.pdf \ -F input_format=pdf \ -F output_format=png \ -F crop_area_height=384 \ -F crop_area_width=1024 \ -F crop_area_x=96 \ -F crop_area_y=370 \ -F dpi=144 \ -F print_page_range=1 \ https://api.pdfcrowd.com/convert/24.04/
import requests with open('report.pdf', 'rb') as input_1: response = requests.post( 'https://api.pdfcrowd.com/convert/24.04/', auth=('demo', 'demo'), data={ 'input_format': 'pdf', 'output_format': 'png', 'crop_area_height': '384', 'crop_area_width': '1024', 'crop_area_x': '96', 'crop_area_y': '370', 'dpi': '144', 'print_page_range': '1', }, files={ 'file': input_1, }, allow_redirects=False, ) response.raise_for_status() with open('chart.png', 'wb') as output_file: output_file.write(response.content)
import { readFile, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "pdf"); form.append("output_format", "png"); form.append("crop_area_height", "384"); form.append("crop_area_width", "1024"); form.append("crop_area_x", "96"); form.append("crop_area_y", "370"); form.append("dpi", "144"); form.append("print_page_range", "1"); form.append("file", new Blob([await readFile("report.pdf")]), basename("report.pdf")); const response = await fetch("https://api.pdfcrowd.com/convert/24.04/", { method: 'POST', headers: { Authorization: 'Basic ' + Buffer.from( username + ':' + apiKey).toString('base64'), }, body: form, redirect: 'manual', }); const body = Buffer.from(await response.arrayBuffer()); if (response.status >= 400) { throw new Error('HTTP ' + response.status + ' ' + response.statusText); } await writeFile("chart.png", body);
import axios from 'axios'; import { readFile, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "pdf"); form.append("output_format", "png"); form.append("crop_area_height", "384"); form.append("crop_area_width", "1024"); form.append("crop_area_x", "96"); form.append("crop_area_y", "370"); form.append("dpi", "144"); form.append("print_page_range", "1"); form.append("file", new Blob([await readFile("report.pdf")]), basename("report.pdf")); try { const response = await axios.post("https://api.pdfcrowd.com/convert/24.04/", form, { auth: { username, password: apiKey }, responseType: 'arraybuffer', maxRedirects: 0, validateStatus: status => status < 400, }); await writeFile("chart.png", response.data); } catch (error) { console.error(error.message); process.exitCode = 1; }
<?php require 'vendor/autoload.php'; use GuzzleHttp\Client; use GuzzleHttp\Psr7\Utils; try { $client = new Client(); $response = $client->post('https://api.pdfcrowd.com/convert/24.04/', [ 'auth' => ['demo', 'demo'], 'multipart' => [ ['name' => 'input_format', 'contents' => 'pdf'], ['name' => 'output_format', 'contents' => 'png'], ['name' => 'crop_area_height', 'contents' => '384'], ['name' => 'crop_area_width', 'contents' => '1024'], ['name' => 'crop_area_x', 'contents' => '96'], ['name' => 'crop_area_y', 'contents' => '370'], ['name' => 'dpi', 'contents' => '144'], ['name' => 'print_page_range', 'contents' => '1'], ['name' => 'file', 'contents' => Utils::tryFopen('report.pdf', 'rb'), 'filename' => basename('report.pdf')], ], 'allow_redirects' => false, 'http_errors' => false, ]); $status = $response->getStatusCode(); if ($status >= 400) { throw new \RuntimeException("HTTP $status " . $response->getReasonPhrase()); } $body = (string) $response->getBody(); if (file_put_contents('chart.png', $body) !== strlen($body)) { throw new \RuntimeException('Failed to write output file'); } } catch (\Throwable $error) { fwrite(STDERR, $error->getMessage() . "\n"); exit(1); }
Use the PDF's CropBox:
curl -f -s -S \ -u 'demo:demo' \ -o cropped-page.png \ -F file=@cropbox.pdf \ -F input_format=pdf \ -F output_format=png \ -F print_page_range=1 \ -F use_cropbox=true \ https://api.pdfcrowd.com/convert/24.04/
import requests with open('cropbox.pdf', 'rb') as input_1: response = requests.post( 'https://api.pdfcrowd.com/convert/24.04/', auth=('demo', 'demo'), data={ 'input_format': 'pdf', 'output_format': 'png', 'print_page_range': '1', 'use_cropbox': 'true', }, files={ 'file': input_1, }, allow_redirects=False, ) response.raise_for_status() with open('cropped-page.png', 'wb') as output_file: output_file.write(response.content)
import { readFile, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "pdf"); form.append("output_format", "png"); form.append("print_page_range", "1"); form.append("use_cropbox", "true"); form.append("file", new Blob([await readFile("cropbox.pdf")]), basename("cropbox.pdf")); const response = await fetch("https://api.pdfcrowd.com/convert/24.04/", { method: 'POST', headers: { Authorization: 'Basic ' + Buffer.from( username + ':' + apiKey).toString('base64'), }, body: form, redirect: 'manual', }); const body = Buffer.from(await response.arrayBuffer()); if (response.status >= 400) { throw new Error('HTTP ' + response.status + ' ' + response.statusText); } await writeFile("cropped-page.png", body);
import axios from 'axios'; import { readFile, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "pdf"); form.append("output_format", "png"); form.append("print_page_range", "1"); form.append("use_cropbox", "true"); form.append("file", new Blob([await readFile("cropbox.pdf")]), basename("cropbox.pdf")); try { const response = await axios.post("https://api.pdfcrowd.com/convert/24.04/", form, { auth: { username, password: apiKey }, responseType: 'arraybuffer', maxRedirects: 0, validateStatus: status => status < 400, }); await writeFile("cropped-page.png", response.data); } catch (error) { console.error(error.message); process.exitCode = 1; }
<?php require 'vendor/autoload.php'; use GuzzleHttp\Client; use GuzzleHttp\Psr7\Utils; try { $client = new Client(); $response = $client->post('https://api.pdfcrowd.com/convert/24.04/', [ 'auth' => ['demo', 'demo'], 'multipart' => [ ['name' => 'input_format', 'contents' => 'pdf'], ['name' => 'output_format', 'contents' => 'png'], ['name' => 'print_page_range', 'contents' => '1'], ['name' => 'use_cropbox', 'contents' => 'true'], ['name' => 'file', 'contents' => Utils::tryFopen('cropbox.pdf', 'rb'), 'filename' => basename('cropbox.pdf')], ], 'allow_redirects' => false, 'http_errors' => false, ]); $status = $response->getStatusCode(); if ($status >= 400) { throw new \RuntimeException("HTTP $status " . $response->getReasonPhrase()); } $body = (string) $response->getBody(); if (file_put_contents('cropped-page.png', $body) !== strlen($body)) { throw new \RuntimeException('Failed to write output file'); } } catch (\Throwable $error) { fwrite(STDERR, $error->getMessage() . "\n"); exit(1); }
Render page 1 of report.pdf into grayscale.png, replacing colors with shades of gray while preserving the page dimensions.
curl -f -s -S \ -u 'demo:demo' \ -o grayscale.png \ -F file=@report.pdf \ -F input_format=pdf \ -F output_format=png \ -F print_page_range=1 \ -F use_grayscale=true \ https://api.pdfcrowd.com/convert/24.04/
import requests with open('report.pdf', 'rb') as input_1: response = requests.post( 'https://api.pdfcrowd.com/convert/24.04/', auth=('demo', 'demo'), data={ 'input_format': 'pdf', 'output_format': 'png', 'print_page_range': '1', 'use_grayscale': 'true', }, files={ 'file': input_1, }, allow_redirects=False, ) response.raise_for_status() with open('grayscale.png', 'wb') as output_file: output_file.write(response.content)
import { readFile, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "pdf"); form.append("output_format", "png"); form.append("print_page_range", "1"); form.append("use_grayscale", "true"); form.append("file", new Blob([await readFile("report.pdf")]), basename("report.pdf")); const response = await fetch("https://api.pdfcrowd.com/convert/24.04/", { method: 'POST', headers: { Authorization: 'Basic ' + Buffer.from( username + ':' + apiKey).toString('base64'), }, body: form, redirect: 'manual', }); const body = Buffer.from(await response.arrayBuffer()); if (response.status >= 400) { throw new Error('HTTP ' + response.status + ' ' + response.statusText); } await writeFile("grayscale.png", body);
import axios from 'axios'; import { readFile, writeFile } from 'node:fs/promises'; import { basename } from 'node:path'; const username = 'demo'; const apiKey = 'demo'; const form = new FormData(); form.append("input_format", "pdf"); form.append("output_format", "png"); form.append("print_page_range", "1"); form.append("use_grayscale", "true"); form.append("file", new Blob([await readFile("report.pdf")]), basename("report.pdf")); try { const response = await axios.post("https://api.pdfcrowd.com/convert/24.04/", form, { auth: { username, password: apiKey }, responseType: 'arraybuffer', maxRedirects: 0, validateStatus: status => status < 400, }); await writeFile("grayscale.png", response.data); } catch (error) { console.error(error.message); process.exitCode = 1; }
<?php require 'vendor/autoload.php'; use GuzzleHttp\Client; use GuzzleHttp\Psr7\Utils; try { $client = new Client(); $response = $client->post('https://api.pdfcrowd.com/convert/24.04/', [ 'auth' => ['demo', 'demo'], 'multipart' => [ ['name' => 'input_format', 'contents' => 'pdf'], ['name' => 'output_format', 'contents' => 'png'], ['name' => 'print_page_range', 'contents' => '1'], ['name' => 'use_grayscale', 'contents' => 'true'], ['name' => 'file', 'contents' => Utils::tryFopen('report.pdf', 'rb'), 'filename' => basename('report.pdf')], ], 'allow_redirects' => false, 'http_errors' => false, ]); $status = $response->getStatusCode(); if ($status >= 400) { throw new \RuntimeException("HTTP $status " . $response->getReasonPhrase()); } $body = (string) $response->getBody(); if (file_put_contents('grayscale.png', $body) !== strlen($body)) { throw new \RuntimeException('Failed to write output file'); } } catch (\Throwable $error) { fwrite(STDERR, $error->getMessage() . "\n"); exit(1); }