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.
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.
invisibleadds 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.
artifactsadds them. - The text of annotations, such as comments and free-text boxes.
annotationsadds 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