Extract text from PDFs from your terminal or shell scripts. The pdf2text command sends your input to PDFCrowd's servers and saves the result locally.
Install the command-line client with pip, or see other installation options.
python -m pip install pdfcrowd-cli
You can run the examples below without account setup. The CLI uses demo credentials unless you have configured your own API credentials. Update the input URLs and filenames as needed.
Commands use POSIX-shell syntax, as in Bash or Zsh, and save results in the current directory.
Fetch a PDF from its URL and save the result locally:
pdf2text --output invoice.txt \ https://your-server.com/invoice.pdf
Upload an existing invoice.pdf file and save invoice.txt:
pdf2text --output invoice.txt \ invoice.pdf
Supply one URL or local file. Use - to read bytes from stdin, including input
piped from another program. Remote URLs must be reachable from PDFCrowd's servers;
upload a local file or send its bytes for input on localhost or a private network.
See Conversion Input
for the supported forms.
For password-protected PDFs, supply the input document's password with
--pdf-password. This password is separate from your
PDFCrowd API key. Use --print-page-range to select pages.
Read invoice.pdf through stdin and save invoice.txt:
pdf2text --output invoice.txt \ - < invoice.pdf
Add options before the input. Command-line options override saved conversion defaults.
pdf2text --print-page-range=1,3 \ --output excerpt.txt \ extraction.pdf
| Purpose | Options |
|---|---|
| Pages to convert | --print-page-range |
| Password-protected input | --pdf-password |
| Layout and paragraphs | --no-layout, --paragraph-mode, --line-spacing-threshold |
| Line endings and page breaks | --eol, --page-break-mode, --custom-page-break |
| Text cleanup | --remove-hyphenation, --remove-empty-lines |
| Extract from a page area | --crop-area |
By default, extraction preserves the PDF's layout with spacing. Enable --no-layout to extract text without preserving columns and positioning.
The PDF password unlocks the input document; it is separate from your PDFCrowd API key.
See the command reference for all options and Configuration for saved defaults. For more tasks, browse the CLI examples.
The result is UTF-8 plain text. A PDF must contain a text layer for extraction; recognizing text in a scanned document requires a separate OCR step.
The examples save the result with
--output PATH.
This preserves an existing file if conversion fails. Shell redirection
(>) opens or truncates its destination before the command runs.
Use --output - to pipe the result to another command.
See the output reference
for terminal behavior and conversion information.
Check the command's exit status before using its output: 0 means success and
a nonzero status means failure. In a shell script, $? immediately after the
conversion contains its status.
Read stderr for the diagnostic message. See errors and exit codes for the meaning of the exit status and reported API errors.
Request rate and concurrency limits depend on your license. Control how quickly
your application submits conversions and how many it runs at once. A
429 response concerns request rate; a 430 response
concerns requests already in progress. The maximum upload size is 300 MB.
The CLI automatically retries a request once after an HTTP 502 or
503 response. Use --retry-count
to change the count, or set it to 0 to disable automatic retries.
Account for these retries when adding retries to a script or job runner.
Enable --debug-log and request
--print-debug-log-url.
This example saves UTF-8 text as response.body and prints the
debug-log URL to stderr:
pdf2text --print-debug-log-url \ --debug-log \ --output response.body \ https://your-server.com/invoice.pdf
The debug log contains conversion settings and processing details. You can also find logs in your conversion history. A local or connection failure may occur before a conversion log is available.
| Problem | Check |
|---|---|
| The PDF cannot be loaded | Check that the URL returns a PDF, rather than HTML or a login page, and is reachable from PDFCrowd's servers. For local files, check the path and read permissions. |
| The PDF requires a password | Set the input document's password with --pdf-password. |
| Text is missing | A scanned PDF may contain images without a text layer. Extracting text from scans requires a separate OCR step. |
| Spacing or reading order is unexpected | Try --no-layout and the paragraph settings. PDF text placement does not always encode a natural reading order. |
For help, contact support
with available diagnostics, the version from pdf2text --version,
and enough detail to reproduce the problem.