pdftotext(1)

โœจ pdftotext(1) โ€” the girlies' guide to turning PDFs into text โœจ

okay bestie, sit down, hydrate, because today we're talking about pdftotext โ€” a member of the Xpdf general commands fam, and honestly? it's giving iconic. it's version 3.03, it converts Portable Document Format (PDF) files into plain text, and it has been carrying the entire "i need the words but not the vibes" industry on its back. ๐Ÿซถ


๐ŸŒธ NAME ๐ŸŒธ

pdftotext โ€” Portable Document Format (PDF) to text converter (version 3.03). that's it, that's the whole name section, she's concise ๐Ÿ’…


๐ŸŽ€ SYNOPSIS ๐ŸŽ€

pdftotext [options] PDF-file [text-file]

like... look at that. options, then the PDF, then where you want the text to go. simple. elegant. main character energy. ๐Ÿ‘‘


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

so here's the tea: Pdftotext converts Portable Document Format (PDF) files to plain text. literally her whole job and she does it well.

she reads the PDF file, PDF-file, and writes a text file, text-file. that's the contract.

  • if text-file is not specified, pdftotext converts file.pdf to file.txt. automatic. no thoughts required. โœจ
  • if text-file is -, the text is sent to stdout โ€” so you can pipe it wherever like the icon you are.
  • if PDF-file is -, it reads the PDF file from stdin. yes she does both. versatile queen ๐Ÿงš

๐Ÿ’– OPTIONS ๐Ÿ’–

one bullet per flag, no skips, no shortcuts, we're doing the full list. buckle up bestie.

  • -f number โ€” specifies the first page to convert. start where you want to start.
  • -l number โ€” specifies the last page to convert. end where you want to end.
  • -r number โ€” specifies the resolution, in DPI. the default is 72 DPI. that's the lowkey important number, don't forget it.
  • -x number โ€” specifies the x-coordinate of the crop area top left corner.
  • -y number โ€” specifies the y-coordinate of the crop area top left corner.
  • -W number โ€” specifies the width of crop area in pixels (default is 0).
  • -H number โ€” specifies the height of crop area in pixels (default is 0).
  • -layout โ€” maintains (as best as possible) the original physical layout of the text. the default instead is to 'undo' physical layout โ€” columns, hyphenation, etc. โ€” and output the text in reading order. so -layout is the "keep my columns pretty" girlie and default is the "just read it to me normally" girlie. ๐Ÿ’…
  • -fixed number โ€” assume fixed-pitch (or tabular) text, with the specified character width (in points). this forces physical layout mode. no escape. ๐Ÿ”ฅ
  • -raw โ€” keep the text in content stream order. this is described as a hack which often "undoes" column formatting, etc. and honestly? use of raw mode is no longer recommended. so like... technically it exists, but she's tired. ๐Ÿ’€
  • -remove-hyphens mode โ€” controls end-of-line hyphen handling. mode is one of:
    • all โ€” remove end-of-line hyphens (U+002D, U+2010, U+FE63, U+FF0D) and Unicode soft hyphens (U+00AD), merging words across lines (default).
    • soft โ€” remove only Unicode soft hyphens (U+00AD), merging words across lines. ASCII and other hyphen characters are preserved.
    • none โ€” keep all end-of-line hyphens and line breaks unchanged.
heads up bestie: this option has no effect in -raw or -layout mode. she simply will not hear you. ๐Ÿ™ˆ
  • -nodiag โ€” discard diagonal text (i.e., text that is not close to one of the 0, 90, 180, or 270 degree axes). this is useful for skipping watermarks drawn on body text. bye watermark ๐Ÿ’…โœจ
  • -htmlmeta โ€” generate a simple HTML file, including the meta information. this simply wraps the text in <pre> and </pre> and prepends the meta headers. it's basic but she's honest about it.
  • -bbox โ€” generate an XHTML file containing bounding box information for each word in the file.
  • -bbox-layout โ€” generate an XHTML file containing bounding box information for each block, line, and word in the file. more detail, more drama.
  • -tsv โ€” generate a TSV file containing the bounding box information for each block, line, and word in the file.
  • -cropbox โ€” use the crop box rather than the media box with -bbox and -bbox-layout.
  • -colspacing number โ€” specifies how much spacing we allow after a word before considering adjacent text to be a new column, measured as a fraction of the font size. current default is 0.7, old releases had a 0.3 default. glow-up fr fr ๐ŸŒˆ
  • -enc encoding-name โ€” sets the encoding to use for text output. this defaults to "UTF-8". as it should. ๐Ÿงš
  • -listenc โ€” lists the available encodings. go off, catalogue queen.
  • -eol unix | dos | mac โ€” sets the end-of-line convention to use for text output. pick your line-ending family.
  • -nopgbrk โ€” don't insert page breaks (form feed characters) between pages. just one long stream, no interruptions. ๐Ÿ’œ
  • -opw password โ€” specify the owner password for the PDF file. providing this will bypass all security restrictions. okay miss thing, use responsibly. ๐Ÿ”ฅ
  • -upw password โ€” specify the user password for the PDF file.
  • -q โ€” don't print any messages or errors. silence. blessed silence. ๐Ÿคซ
  • -v โ€” print copyright and version information.
  • -h โ€” print usage information. (and yup, -help and --help are equivalent, so you have options within your options ๐Ÿ’…)

๐Ÿ˜ญ BUGS ๐Ÿ˜ญ

and here's the sad part, bestie: some PDF files contain fonts whose encodings have been mangled beyond recognition. there is no way โ€” short of OCR โ€” to extract text from these files. she literally cannot do it. it's not a skill issue, it's a file issue. ๐Ÿ’€


๐ŸŒˆ EXIT CODES ๐ŸŒˆ

the Xpdf tools use the following exit codes:

  • 0 โ€” No error. ๐ŸŽ‰
  • 1 โ€” Error opening a PDF file.
  • 2 โ€” Error opening an output file.
  • 3 โ€” Error related to PDF permissions.
  • 99 โ€” Other error.

๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

the pdftotext software and documentation are copyright 1996-2011 Glyph & Cog, LLC. respect the elders, they built the house we live in. ๐Ÿซถ


๐Ÿ’… SEE ALSO ๐Ÿ’…

if you liked pdftotext, you will be obsessed with her siblings:


okay that's the whole page, no cap. this manual page is dated 15 August 2011 and exists under the pdftotext(1) banner โ€” so go forth, convert your PDFs, and slay. periodt. ๐ŸŒธโœจ๐ŸŽ€๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from