Introduction
pdfcpu is a pure Go library and command-line tool for processing PDF files. It covers the full spectrum of common PDF operations without relying on external tools like Ghostscript or Poppler.
What pdfcpu Does
- Merges, splits, rotates, and reorders PDF pages
- Adds text and image watermarks or stamps to pages
- Encrypts and decrypts PDFs with AES-256 or RC4
- Validates PDF files against the PDF specification
- Optimizes file size by removing redundant objects and compressing streams
Architecture Overview
pdfcpu is written entirely in Go with no CGo dependencies. It implements a PDF parser and writer that handles the full PDF object model including cross-reference tables, object streams, and incremental updates. The CLI wraps the library API and supports batch operations across multiple files.
Self-Hosting & Configuration
- Install via
go installor download prebuilt binaries from GitHub Releases - Available in Homebrew, AUR, and Docker Hub
- No configuration file required; all options are passed via CLI flags
- The Go library can be imported directly into Go projects
- Supports stdin/stdout piping for integration into shell pipelines
Key Features
- Pure Go implementation with zero external dependencies
- Full PDF spec compliance including PDF 2.0 support
- Batch processing support for operating on multiple files at once
- Page-level operations: extract, insert, remove, rotate individual pages
- Form filling and flattening for automated document workflows
Comparison with Similar Tools
- Ghostscript — C-based and heavyweight; pdfcpu is a single Go binary with no system dependencies
- qpdf — C++ PDF transformation tool; pdfcpu offers a similar feature set in pure Go
- PyPDF — Python library; pdfcpu is faster and works as both a CLI and Go library
- pdftk — Java-based PDF toolkit; pdfcpu has no JVM requirement and is easier to deploy
- Stirling PDF — web-based PDF suite; pdfcpu is a CLI/library for automation and scripting
FAQ
Q: Does pdfcpu support password-protected PDFs? A: Yes. It can encrypt and decrypt PDFs using AES-128, AES-256, or RC4 encryption.
Q: Can I use pdfcpu as a Go library? A: Yes. The library API mirrors the CLI functionality and is well-documented.
Q: Does it handle scanned PDFs or OCR? A: No. pdfcpu works with the PDF structure, not image content. Use a separate OCR tool first.
Q: Is PDF 2.0 supported? A: Yes. pdfcpu supports reading and writing PDF 2.0 compliant files.