Skip to main content
Version: 9.x

Extract the text

Returns the text a PDF shows, as a UTF-8 .txt file or as Markdown: for search indexes, language models, or a diff between two versions.

POST/forms/pdf/extract-text
filesfile[]required

The PDFs.

archivesfile[]

ZIP files Gotenberg unpacks: each entry counts as a file uploaded under files.

URLs Gotenberg downloads first, as if you had uploaded the files. Each entry takes a url, and optionally extraHttpHeaders and filename.

The pages to read, in the order given. Markdown reads them in document order.

Default: all

formatstring

text, or markdown for a .md file with the headings, lists, tables and links the PDF's structure gives. The Chromium and LibreOffice routes print a tagged PDF for Markdown.

Default: text

invisibleboolean

Adds the text layer a searchable scan carries under its image. Gotenberg recognizes no text in an image.

Default: false

artifactsboolean

Adds the headers, footers, page numbers and stamps the PDF marks as artifacts.

Default: false

Adds the text of annotations, such as comments and free-text boxes.

Default: false

The text file, or a ZIP of the text files when there are several.

The route also takes the headers. An error answers a status and a message: see Errors.

Extract every page​

curl \
--request POST http://localhost:3000/forms/pdf/extract-text \
--form files=@report.pdf \
-o report.txt

The file takes the name of the PDF: report.txt. A form feed separates the pages, as with pdftotext, so you can split it back into pages. Several PDFs come back in a ZIP.

Extract some pages​

curl \
--request POST http://localhost:3000/forms/pdf/extract-text \
--form files=@report.pdf \
--form pages=1 \
-o report.txt

pages takes a page selection, read in the order it gives.

Extract as Markdown​

format set to markdown returns a .md file that keeps the structure: headings, paragraphs, lists, tables, block quotes, bold and italic text, code, and links.

curl \
--request POST http://localhost:3000/forms/pdf/extract-text \
--form files=@report.pdf \
--form format=markdown \
-o report.md

A tagged PDF gives the structure it carries. An untagged one gives its layout alone, which Gotenberg reads as auto-tagging does: larger text becomes a heading, and the rest paragraphs. Markdown reads the pages in document order, without a form feed between them. An image comes as its alternative text, and a scanned page reads as empty.

For a web page or an office document, convert and extract in one request: the Chromium and LibreOffice routes print a tagged PDF when a stage asks for Markdown, whatever nativeTaggedPdf says. Turning a URL into Markdown for a language model takes one request:

curl \
--request POST http://localhost:3000/forms/chromium/convert/url \
--form url=https://example.com \
--form 'stages=[
{ "op": "extract-text", "format": "markdown" }
]' \
-o example.zip

The ZIP holds the tagged PDF and its Markdown. The wait options let a page finish rendering first.

Choose what counts as text​

Gotenberg reads what the page shows. It leaves out:

  • The text layer a searchable scan carries under its image. invisible adds it. Gotenberg recognizes no text in an image: a scanned page without that layer reads as empty.
  • Headers, footers, page numbers and stamps the PDF marks as artifacts. artifacts adds them.
  • The text of annotations, such as comments and free-text boxes. annotations adds it.
curl \
--request POST http://localhost:3000/forms/pdf/extract-text \
--form files=@report.pdf \
--form invisible=true \
--form artifacts=true \
--form annotations=true \
-o report.txt

Extract after other stages​

extract-text comes last in a list of stages. On its own, it answers the text only. After other stages, the ZIP holds the PDF too. A conversion takes the stage too: a LibreOffice conversion with extract-text returns a Word document as a PDF and its text, in a ZIP.

In a list of stages​

The stage also runs in a list on /forms/pdf/pipe, and on the PDFs a Chromium or LibreOffice conversion makes, in its stages field:

curl \
--request POST http://localhost:3000/forms/pdf/pipe \
--form files=@report.pdf \
--form 'stages=[
{ "op": "extract-text", "pages": "1" }
]' \
-o report.txt