catpdf
A command-line utility written in Go that concatenates (catenates) PDF files.
Installation
go install github.com/Michael-F-Ellis/catpdf@latest
Or build from source:
git clone https://github.com/Michael-F-Ellis/catpdf.git
cd catpdf
go build -o catpdf main.go
sudo mv catpdf /usr/local/bin/
Usage
catpdf file1.pdf file2.pdf file3.pdf > combined.pdf
The utility reads PDF files in the order they are provided as command-line arguments and writes the concatenated PDF to standard output.
Examples
Concatenate two PDFs:
catpdf chapter1.pdf chapter2.pdf > book.pdf
Concatenate multiple PDFs:
catpdf *.pdf > all.pdf
Use in a pipeline (though direct file arguments are preferred):
find . -name "*.pdf" -print0 | xargs -0 catpdf > combined.pdf
Requirements
- Go 1.16 or later (for building from source)
- The
pdfcpu library is used internally for PDF processing
How it works
catpdf uses the pdfcpu library to merge PDF files. It opens each input file, reads them as streams, and merges them directly to standard output without creating intermediate files on disk (except in memory).
Error handling
- If no arguments are provided, usage instructions are displayed
- If a file cannot be opened, an error is printed and the program exits
- If a file is not a valid PDF, an error is printed and the program exits
- The program exits with a non-zero status on error
License
See LICENSE file.
Contributing
Contributions are welcome! Please open an issue or pull request on GitHub.