Extract text from a PDF.

Synopsis

pdftotext [options] <input.pdf> [output.txt]

Description

Extracts text from a PDF via pdf.js. Writes <input>.txt next to the input when no output file is given; pass '-' to write to stdout instead.

Options

-f N First page to extract.

-l N Last page to extract (clamped to the page count).

-layout Preserve the page's column layout by padding with spaces.

-raw Content-stream order (the default here; accepted for parity).

-nopgbrk Do not emit a form feed between pages.

-enc NAME Text encoding; only UTF-8 is supported.

-eol STYLE Line endings: unix (default), dos, or mac.

-q Do not print the output filename on success.

Examples

$ pdftotext report.pdf -

Print the PDF's text to stdout.

$ pdftotext -layout invoice.pdf -

Keep table columns aligned in the output.

$ pdftotext -f 2 -l 5 book.pdf part.txt

Extract only pages 2-5.

Notes

Scanned PDFs carry no text layer and cannot be OCR'd by this command; rasterize with pdftoppm -png and read the pages as images instead.

See Also

pdftoppm, pdftocairo, magick