pdfcpu
PDF tooling for Go and the command line.
pdfcpu is a Go library and command-line tool for working with PDF files. It can merge, split, encrypt, watermark, extract images and fonts, fill forms, and handle most PDF operations with no external dependencies.
pdfcpu is a library for working with PDF files, written in the Go programming language. It can be used both as a command-line tool that you run in a terminal and as a code library that developers import into their own Go programs. It works with all versions of the PDF format, with support for the most recent version (PDF 2.0) still being actively improved.
The tool covers a wide range of PDF operations. On the basic end, you can validate a PDF against the standard, merge multiple PDF files into one, split a single PDF into separate files, or trim it down to specific pages. It also handles things that are more involved, like encrypting and decrypting password-protected files, changing permission settings, adding watermarks or stamps to pages, resizing and rotating pages, and cropping page boundaries.
Beyond editing existing files, pdfcpu can also extract content from PDFs: you can pull out embedded images, fonts, or metadata as separate files. There is also a form handling feature for reading and filling PDF forms, and a booklets feature for rearranging pages into a printable booklet layout. The full list of supported commands is extensive and documented on the project's website.
The design priorities are correctness, stable behavior, and avoiding external dependencies, meaning the library does not rely on third-party PDF toolkits or system-level PDF software. This makes it straightforward to include in a Go project without additional installation steps for end users.
For command-line use, each sub-command accepts a help flag for details. For developers using it as a Go library, there is package documentation and a set of example files in the repository. The project is open source under the Apache 2.0 license and welcomes contributions and bug reports, particularly when reports include a sample PDF that demonstrates the issue.
Where it fits
- Merge multiple PDF reports into one file from the command line without installing Adobe software
- Encrypt a PDF with a password and restrict permissions like printing or copying, programmatically in Go
- Extract all embedded images from a PDF as separate files for reuse or inspection
- Fill in a PDF form programmatically with data pulled from a database using the Go library