pdftotext in Termux – Convert PDF Files to Text

pdftotext is a command-line tool that lets you extract text from PDF files in Termux. It converts PDF documents into plain text files. You can also extract text from specific pages, maintain the original layout, and choose different output formats.

Here’s what you can do with pdftotext in Termux:

  • Convert PDF files into text files.
  • Extract text from specific pages.
  • Convert multiple pages at once.
  • Maintain the original document layout.
  • Choose different text encodings.
  • Extract text without page breaks.
  • Display URLs found inside PDF files.
  • Generate HTML and TSV output.
  • Work with password-protected PDF files.

Install pdftotext in Termux

Below is the simple command to install pdftotext in Termux, just copy and run the command in Termux.

First, update and upgrade the packages:

pkg update && pkg upgrade -y

Install Poppler:

pkg install poppler -y

pdftotext is now ready to use in Termux.

Use pdftotext in Termux

Use the following commands to convert PDF files into text and explore different pdftotext options.

Convert a PDF file to a text file:

pdftotext file.pdf

Convert a PDF file and choose an output file name:

pdftotext file.pdf output.txt

Extract text from a specific page:

pdftotext -f 2 -l 2 file.pdf output.txt

Extract text from pages 1 to 5:

pdftotext -f 1 -l 5 file.pdf output.txt

Maintain the original document layout:

pdftotext -layout file.pdf output.txt

Extract text in the original content stream order:

pdftotext -raw file.pdf output.txt

Convert a PDF without inserting page breaks:

pdftotext -nopgbrk file.pdf output.txt

Extract text and include URLs:

pdftotext -urls file.pdf output.txt

Generate HTML output with PDF metadata:

pdftotext -htmlmeta file.pdf output.html

Generate TSV output with text position information:

pdftotext -tsv file.pdf output.tsv

Choose the output text encoding:

pdftotext -enc UTF-8 file.pdf output.txt

List available text encodings:

pdftotext -listenc

Display the bounding box of each word:

pdftotext -bbox file.pdf output.html

Display the bounding box with additional layout information:

pdftotext -bbox-layout file.pdf output.html

Convert a password-protected PDF:

pdftotext -upw YOUR_PASSWORD file.pdf output.txt

Show version information:

pdftotext -v

Show the help menu:

pdftotext -h

These options give you more control over PDF conversion, page selection, and text output.

End Note

pdftotext is a useful command-line tool for extracting text from PDF documents in Termux. Its different options give you more control over page selection, text layout, encoding, and output formats.

SHARE THIS POST: