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.
# Homebrew (macOS/Linux)brew install yfedoseev/tap/pdf-oxide
# Cargocargo install pdf_oxide_cliText Extraction
Extract all text from a PDF:
pdf-oxide text document.pdfPipe the output to a file or another command:
pdf-oxide text document.pdf > output.txtpdf-oxide text document.pdf | grep "important"Extract specific pages:
pdf-oxide text document.pdf --pages 1-3pdf-oxide text document.pdf --pages 1,5,10Get JSON output for programmatic use:
pdf-oxide text document.pdf --jsonMarkdown Conversion
Convert a PDF to Markdown while preserving structure:
pdf-oxide markdown report.pdf -o report.mdThis 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:
pdf-oxide merge a.pdf b.pdf c.pdf -o combined.pdfMerge all PDFs in a directory:
pdf-oxide merge *.pdf -o all.pdfControl the order by listing files explicitly. The first file appears first in the output.
Splitting PDFs
Split a PDF into individual pages:
pdf-oxide split document.pdf -o pages/Extract a page range:
pdf-oxide split document.pdf --pages 1-5 -o first-five.pdfSearching
Search for text with regex support:
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:
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:
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:
--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 PDFsBatch Processing
Combine commands in shell scripts for batch operations:
#!/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"doneProcess files from a list:
cat files.txt | while read file; do pdf-oxide text "$file"doneAvailable Commands
The CLI provides 22 commands for common PDF operations:
| Command | Description |
|---|---|
text | Extract text from PDF |
markdown | Convert to Markdown |
merge | Combine multiple PDFs |
split | Split into individual pages |
search | Search with regex patterns |
images | Extract embedded images |
forms | Fill PDF form fields |
pages | Get page count and metadata |
info | Display PDF information |
validate | Check PDF integrity |
compress | Reduce file size |
encrypt | Add password protection |
decrypt | Remove password protection |
rotate | Rotate pages |
crop | Crop page boundaries |
watermark | Add watermarks |
metadata | Edit document metadata |
bookmarks | Extract or modify bookmarks |
fonts | List embedded fonts |
permissions | View or change permissions |
sign | Add digital signatures |
flatten | Flatten 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