BloodwebMicroservices Sign in
← PDF to text

Extract text from a PDF with curl

Extract the text from a PDF, keeping the layout or as plain reading order, for all pages or a range. Here is the whole call with curl, with the output it produced when we ran it.

Before you start

The code

Save it as pdf-to-text.sh and run bash pdf-to-text.sh.

curl -sS --fail-with-body \
  -H "Authorization: Bearer $BLOODWEB_KEY" \
  -F file=@report.pdf \
  -F pages=1-3 \
  https://bloodweb.net/api/v1/pdf-to-text \
  -o report.txt

What you get

Tested 19 October 2026: this exact code ran against our test copy of the API, which runs the same service code as bloodweb.net, and produced this.

It writes report.txt: a text file, 1 KB.

Quarterly report, page 1
A sample page made for the code examples.

Quarterly report, page 2
A sample page made for the code examples.

Quarterly report, page 3
A sample page made for the code examples.

Change the call

Every option the PDF to text takes. Add or change them the same way as the ones in the code.

If it fails

A failed call is not charged. The answer is JSON with an error object; curl stops with an error, and that JSON lands in report.txt instead of the result, so open it as text to read the reason. The usual ones:

Every code and its fix is in the docs.

Next