These examples demonstrate common PDF to Text 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.
curl -f -s -S \ -u 'demo:demo' \ -o invoice.txt \ -F file=@invoice.pdf \ -F input_format=pdf \ -F output_format=txt \ 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': 'txt', }, files={ 'file': input_1, }, allow_redirects=False, ) response.raise_for_status() with open('invoice.txt', '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", "txt"); 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.txt", 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", "txt"); 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.txt", 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' => 'txt'], ['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.txt', $body) !== strlen($body)) { throw new \RuntimeException('Failed to write output file'); } } catch (\Throwable $error) { fwrite(STDERR, $error->getMessage() . "\n"); exit(1); }
curl -f -s -S \ -u 'demo:demo' \ -o invoice.txt \ -F url=https://your-server.com/invoice.pdf \ -F input_format=pdf \ -F output_format=txt \ 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': 'txt', 'url': 'https://your-server.com/invoice.pdf', }, allow_redirects=False, ) response.raise_for_status() with open('invoice.txt', '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", "txt"); 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.txt", 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", "txt"); 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.txt", 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' => 'txt'], ['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.txt', $body) !== strlen($body)) { throw new \RuntimeException('Failed to write output file'); } } catch (\Throwable $error) { fwrite(STDERR, $error->getMessage() . "\n"); exit(1); }
These examples upload extraction.pdf, a three-page document with a two-column article, wrapped paragraphs, and invoice fields.
Extract pages 1 and 3 of extraction.pdf into excerpt.txt.
curl -f -s -S \ -u 'demo:demo' \ -o excerpt.txt \ -F file=@extraction.pdf \ -F input_format=pdf \ -F output_format=txt \ -F print_page_range=1,3 \ https://api.pdfcrowd.com/convert/24.04/
import requests with open('extraction.pdf', 'rb') as input_1: response = requests.post( 'https://api.pdfcrowd.com/convert/24.04/', auth=('demo', 'demo'), data={ 'input_format': 'pdf', 'output_format': 'txt', 'print_page_range': '1,3', }, files={ 'file': input_1, }, allow_redirects=False, ) response.raise_for_status() with open('excerpt.txt', '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", "txt"); form.append("print_page_range", "1,3"); form.append("file", new Blob([await readFile("extraction.pdf")]), basename("extraction.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("excerpt.txt", 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", "txt"); form.append("print_page_range", "1,3"); form.append("file", new Blob([await readFile("extraction.pdf")]), basename("extraction.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("excerpt.txt", 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' => 'txt'], ['name' => 'print_page_range', 'contents' => '1,3'], ['name' => 'file', 'contents' => Utils::tryFopen('extraction.pdf', 'rb'), 'filename' => basename('extraction.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('excerpt.txt', $body) !== strlen($body)) { throw new \RuntimeException('Failed to write output file'); } } catch (\Throwable $error) { fwrite(STDERR, $error->getMessage() . "\n"); exit(1); }
Extract the article on page 1 into article.txt without spacing that recreates the PDF's columns. For tables, the default layout mode usually preserves column alignment better.
curl -f -s -S \ -u 'demo:demo' \ -o article.txt \ -F file=@extraction.pdf \ -F input_format=pdf \ -F output_format=txt \ -F no_layout=true \ -F print_page_range=1 \ https://api.pdfcrowd.com/convert/24.04/
import requests with open('extraction.pdf', 'rb') as input_1: response = requests.post( 'https://api.pdfcrowd.com/convert/24.04/', auth=('demo', 'demo'), data={ 'input_format': 'pdf', 'output_format': 'txt', 'no_layout': 'true', 'print_page_range': '1', }, files={ 'file': input_1, }, allow_redirects=False, ) response.raise_for_status() with open('article.txt', '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", "txt"); form.append("no_layout", "true"); form.append("print_page_range", "1"); form.append("file", new Blob([await readFile("extraction.pdf")]), basename("extraction.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("article.txt", 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", "txt"); form.append("no_layout", "true"); form.append("print_page_range", "1"); form.append("file", new Blob([await readFile("extraction.pdf")]), basename("extraction.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("article.txt", 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' => 'txt'], ['name' => 'no_layout', 'contents' => 'true'], ['name' => 'print_page_range', 'contents' => '1'], ['name' => 'file', 'contents' => Utils::tryFopen('extraction.pdf', 'rb'), 'filename' => basename('extraction.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('article.txt', $body) !== strlen($body)) { throw new \RuntimeException('Failed to write output file'); } } catch (\Throwable $error) { fwrite(STDERR, $error->getMessage() . "\n"); exit(1); }
Extract page 2 into paragraphs.txt, joining wrapped lines with paragraph detection and removing line-end hyphens. For example, infor- followed by mation becomes information. Paragraph detection depends on the document's layout.
curl -f -s -S \ -u 'demo:demo' \ -o paragraphs.txt \ -F file=@extraction.pdf \ -F input_format=pdf \ -F output_format=txt \ -F paragraph_mode=bounding-box \ -F print_page_range=2 \ -F remove_hyphenation=true \ https://api.pdfcrowd.com/convert/24.04/
import requests with open('extraction.pdf', 'rb') as input_1: response = requests.post( 'https://api.pdfcrowd.com/convert/24.04/', auth=('demo', 'demo'), data={ 'input_format': 'pdf', 'output_format': 'txt', 'paragraph_mode': 'bounding-box', 'print_page_range': '2', 'remove_hyphenation': 'true', }, files={ 'file': input_1, }, allow_redirects=False, ) response.raise_for_status() with open('paragraphs.txt', '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", "txt"); form.append("paragraph_mode", "bounding-box"); form.append("print_page_range", "2"); form.append("remove_hyphenation", "true"); form.append("file", new Blob([await readFile("extraction.pdf")]), basename("extraction.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("paragraphs.txt", 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", "txt"); form.append("paragraph_mode", "bounding-box"); form.append("print_page_range", "2"); form.append("remove_hyphenation", "true"); form.append("file", new Blob([await readFile("extraction.pdf")]), basename("extraction.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("paragraphs.txt", 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' => 'txt'], ['name' => 'paragraph_mode', 'contents' => 'bounding-box'], ['name' => 'print_page_range', 'contents' => '2'], ['name' => 'remove_hyphenation', 'contents' => 'true'], ['name' => 'file', 'contents' => Utils::tryFopen('extraction.pdf', 'rb'), 'filename' => basename('extraction.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('paragraphs.txt', $body) !== strlen($body)) { throw new \RuntimeException('Failed to write output file'); } } catch (\Throwable $error) { fwrite(STDERR, $error->getMessage() . "\n"); exit(1); }
Crop away the headers and footers on every page, or extract only the customer, invoice, and reference fields on page 3.
The coordinates below match a 612 × 792 point (US Letter) page. Measure X and Y from the top-left corner; 72 points equal one inch. Adjust the regions for your PDF.
Exclude headers and footers:
curl -f -s -S \ -u 'demo:demo' \ -o body.txt \ -F file=@extraction.pdf \ -F input_format=pdf \ -F output_format=txt \ -F crop_area_height=648 \ -F crop_area_width=540 \ -F crop_area_x=36 \ -F crop_area_y=72 \ https://api.pdfcrowd.com/convert/24.04/
import requests with open('extraction.pdf', 'rb') as input_1: response = requests.post( 'https://api.pdfcrowd.com/convert/24.04/', auth=('demo', 'demo'), data={ 'input_format': 'pdf', 'output_format': 'txt', 'crop_area_height': '648', 'crop_area_width': '540', 'crop_area_x': '36', 'crop_area_y': '72', }, files={ 'file': input_1, }, allow_redirects=False, ) response.raise_for_status() with open('body.txt', '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", "txt"); form.append("crop_area_height", "648"); form.append("crop_area_width", "540"); form.append("crop_area_x", "36"); form.append("crop_area_y", "72"); form.append("file", new Blob([await readFile("extraction.pdf")]), basename("extraction.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("body.txt", 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", "txt"); form.append("crop_area_height", "648"); form.append("crop_area_width", "540"); form.append("crop_area_x", "36"); form.append("crop_area_y", "72"); form.append("file", new Blob([await readFile("extraction.pdf")]), basename("extraction.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("body.txt", 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' => 'txt'], ['name' => 'crop_area_height', 'contents' => '648'], ['name' => 'crop_area_width', 'contents' => '540'], ['name' => 'crop_area_x', 'contents' => '36'], ['name' => 'crop_area_y', 'contents' => '72'], ['name' => 'file', 'contents' => Utils::tryFopen('extraction.pdf', 'rb'), 'filename' => basename('extraction.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('body.txt', $body) !== strlen($body)) { throw new \RuntimeException('Failed to write output file'); } } catch (\Throwable $error) { fwrite(STDERR, $error->getMessage() . "\n"); exit(1); }
Extract an invoice field block:
curl -f -s -S \ -u 'demo:demo' \ -o fields.txt \ -F file=@extraction.pdf \ -F input_format=pdf \ -F output_format=txt \ -F crop_area_height=70 \ -F crop_area_width=300 \ -F crop_area_x=36 \ -F crop_area_y=290 \ -F print_page_range=3 \ https://api.pdfcrowd.com/convert/24.04/
import requests with open('extraction.pdf', 'rb') as input_1: response = requests.post( 'https://api.pdfcrowd.com/convert/24.04/', auth=('demo', 'demo'), data={ 'input_format': 'pdf', 'output_format': 'txt', 'crop_area_height': '70', 'crop_area_width': '300', 'crop_area_x': '36', 'crop_area_y': '290', 'print_page_range': '3', }, files={ 'file': input_1, }, allow_redirects=False, ) response.raise_for_status() with open('fields.txt', '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", "txt"); form.append("crop_area_height", "70"); form.append("crop_area_width", "300"); form.append("crop_area_x", "36"); form.append("crop_area_y", "290"); form.append("print_page_range", "3"); form.append("file", new Blob([await readFile("extraction.pdf")]), basename("extraction.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("fields.txt", 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", "txt"); form.append("crop_area_height", "70"); form.append("crop_area_width", "300"); form.append("crop_area_x", "36"); form.append("crop_area_y", "290"); form.append("print_page_range", "3"); form.append("file", new Blob([await readFile("extraction.pdf")]), basename("extraction.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("fields.txt", 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' => 'txt'], ['name' => 'crop_area_height', 'contents' => '70'], ['name' => 'crop_area_width', 'contents' => '300'], ['name' => 'crop_area_x', 'contents' => '36'], ['name' => 'crop_area_y', 'contents' => '290'], ['name' => 'print_page_range', 'contents' => '3'], ['name' => 'file', 'contents' => Utils::tryFopen('extraction.pdf', 'rb'), 'filename' => basename('extraction.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('fields.txt', $body) !== strlen($body)) { throw new \RuntimeException('Failed to write output file'); } } catch (\Throwable $error) { fwrite(STDERR, $error->getMessage() . "\n"); exit(1); }
The default output has no page separators. Insert form-feed characters (\f) for processing text by page, or add a visible --- PAGE BREAK --- marker on its own line.
Use form-feed separators:
curl -f -s -S \ -u 'demo:demo' \ -o pages.txt \ -F file=@extraction.pdf \ -F input_format=pdf \ -F output_format=txt \ -F page_break_mode=default \ https://api.pdfcrowd.com/convert/24.04/
import requests with open('extraction.pdf', 'rb') as input_1: response = requests.post( 'https://api.pdfcrowd.com/convert/24.04/', auth=('demo', 'demo'), data={ 'input_format': 'pdf', 'output_format': 'txt', 'page_break_mode': 'default', }, files={ 'file': input_1, }, allow_redirects=False, ) response.raise_for_status() with open('pages.txt', '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", "txt"); form.append("page_break_mode", "default"); form.append("file", new Blob([await readFile("extraction.pdf")]), basename("extraction.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("pages.txt", 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", "txt"); form.append("page_break_mode", "default"); form.append("file", new Blob([await readFile("extraction.pdf")]), basename("extraction.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("pages.txt", 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' => 'txt'], ['name' => 'page_break_mode', 'contents' => 'default'], ['name' => 'file', 'contents' => Utils::tryFopen('extraction.pdf', 'rb'), 'filename' => basename('extraction.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('pages.txt', $body) !== strlen($body)) { throw new \RuntimeException('Failed to write output file'); } } catch (\Throwable $error) { fwrite(STDERR, $error->getMessage() . "\n"); exit(1); }
Use visible separators:
curl -f -s -S \ -u 'demo:demo' \ -o separated.txt \ -F file=@extraction.pdf \ -F input_format=pdf \ -F output_format=txt \ --form-string 'custom_page_break= --- PAGE BREAK --- ' \ -F page_break_mode=custom \ https://api.pdfcrowd.com/convert/24.04/
import requests with open('extraction.pdf', 'rb') as input_1: response = requests.post( 'https://api.pdfcrowd.com/convert/24.04/', auth=('demo', 'demo'), data={ 'input_format': 'pdf', 'output_format': 'txt', 'custom_page_break': """ --- PAGE BREAK --- """, 'page_break_mode': 'custom', }, files={ 'file': input_1, }, allow_redirects=False, ) response.raise_for_status() with open('separated.txt', '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", "txt"); form.append("custom_page_break", new Blob([` --- PAGE BREAK --- `]), ''); form.append("page_break_mode", "custom"); form.append("file", new Blob([await readFile("extraction.pdf")]), basename("extraction.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("separated.txt", 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", "txt"); form.append("custom_page_break", new Blob([` --- PAGE BREAK --- `]), ''); form.append("page_break_mode", "custom"); form.append("file", new Blob([await readFile("extraction.pdf")]), basename("extraction.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("separated.txt", 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' => 'txt'], ['name' => 'custom_page_break', 'contents' => ' --- PAGE BREAK --- '], ['name' => 'page_break_mode', 'contents' => 'custom'], ['name' => 'file', 'contents' => Utils::tryFopen('extraction.pdf', 'rb'), 'filename' => basename('extraction.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('separated.txt', $body) !== strlen($body)) { throw new \RuntimeException('Failed to write output file'); } } catch (\Throwable $error) { fwrite(STDERR, $error->getMessage() . "\n"); exit(1); }