Skip to content

PDF Command-Line Tools You Should Know

I needed to extract text from a dozen PDFs for a report. Opening each in Preview, copying the text, and pasting into a text editor was tedious. The workflow doesn’t scale. When you have hundreds of files or need to automate text extraction, GUI applications become a bottleneck.

I found pdf-oxide. It’s a command-line tool that handles 22 common PDF operations. Text extraction, merging, splitting, searching, form filling—all from the terminal.

Installation

Install via Homebrew or Cargo. The binary is compiled to Rust, so it’s fast and has no runtime dependencies.

Terminal
# Homebrew (macOS/Linux)
brew install yfedoseev/tap/pdf-oxide
# Cargo
cargo install pdf_oxide_cli

Text Extraction

Extract all text from a PDF:

Terminal
pdf-oxide text document.pdf

Pipe the output to a file or another command:

Terminal
pdf-oxide text document.pdf > output.txt
pdf-oxide text document.pdf | grep "important"

Extract specific pages:

Terminal
pdf-oxide text document.pdf --pages 1-3
pdf-oxide text document.pdf --pages 1,5,10

Get JSON output for programmatic use:

Terminal
pdf-oxide text document.pdf --json

Markdown Conversion

Convert a PDF to Markdown while preserving structure:

Terminal
pdf-oxide markdown report.pdf -o report.md

This extracts headings, paragraphs, lists, and tables. The output is readable Markdown that works with most static site generators and documentation tools.

Merging PDFs

Combine multiple PDFs into one:

Terminal
pdf-oxide merge a.pdf b.pdf c.pdf -o combined.pdf

Merge all PDFs in a directory:

Terminal
pdf-oxide merge *.pdf -o all.pdf

Control the order by listing files explicitly. The first file appears first in the output.

Splitting PDFs

Split a PDF into individual pages:

Terminal
pdf-oxide split document.pdf -o pages/

Extract a page range:

Terminal
pdf-oxide split document.pdf --pages 1-5 -o first-five.pdf

Searching

Search for text with regex support:

Terminal
pdf-oxide search contract.pdf "termination|cancel"
pdf-oxide search report.pdf "invoice \d{4,}"

This searches across all pages and reports matches with page numbers.

Image Extraction

Extract images from a PDF:

Terminal
pdf-oxide images document.pdf -o images/

Images are saved in their original format. The tool preserves quality and resolution.

Form Filling

Fill PDF form fields from the command line:

Terminal
pdf-oxide forms w2.pdf --fill "name=John Doe"
pdf-oxide forms tax.pdf --fill "ssn=123-45-6789" --fill "income=50000"

Multiple fields are specified with separate --fill flags. The field names match the internal PDF form field names.

Global Options

Most commands support these options:

Options
--pages 1-5 # Process specific pages or ranges
--json # Output in JSON format
-o output.file # Specify output file path
--password secret # Open password-protected PDFs

Batch Processing

Combine commands in shell scripts for batch operations:

Terminal
#!/bin/bash
for pdf in *.pdf; do
echo "Processing $pdf"
pdf-oxide text "$pdf" > "${pdf%.pdf}.txt"
pdf-oxide markdown "$pdf" -o "${pdf%.pdf}.md"
done

Process files from a list:

Terminal
cat files.txt | while read file; do
pdf-oxide text "$file"
done

Available Commands

The CLI provides 22 commands for common PDF operations:

CommandDescription
textExtract text from PDF
markdownConvert to Markdown
mergeCombine multiple PDFs
splitSplit into individual pages
searchSearch with regex patterns
imagesExtract embedded images
formsFill PDF form fields
pagesGet page count and metadata
infoDisplay PDF information
validateCheck PDF integrity
compressReduce file size
encryptAdd password protection
decryptRemove password protection
rotateRotate pages
cropCrop page boundaries
watermarkAdd watermarks
metadataEdit document metadata
bookmarksExtract or modify bookmarks
fontsList embedded fonts
permissionsView or change permissions
signAdd digital signatures
flattenFlatten annotations

Run pdf-oxide --help to see all commands and options.

Final Words + More Resources

My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me

Here are also the most important links from this article along with some further resources that will help you in this scope:

Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!

Comments