pdfcpu

Logo

PDF tooling for Go and the command line.

View the Project on GitHub pdfcpu/pdfcpu


Changelog
Future Directions

Piping

Many pdfcpu commands accept - as a conventional Unix placeholder for standard input or standard output.

Use - in an input PDF position to read a PDF from stdin.

Use - in an output PDF position to write a PDF to stdout.

This makes pdfcpu fit naturally into shell pipelines, object storage workflows and container jobs.

Notes

The two - arguments in a command like this have different meanings:

pdfcpu optimize - -

The first - is the input PDF read from stdin.

The second - is the output PDF written to stdout.

For commands with non-PDF arguments, - support applies to PDF input and output positions only. JSON files, image files, CSV files, font files and other auxiliary inputs remain regular file arguments unless documented otherwise.

Avoid adding a separate optimize step after commands that already write an optimized PDF. For example, merge, stamp, watermark, trim and rotate produce processed PDF output directly. Use optimize as its own pipeline step when optimization is the operation you want to perform.

Support Matrix

The matrix describes PDF piping support for command input and output positions. Auxiliary files such as JSON, CSV, images, fonts and stamp source PDFs are regular file arguments unless noted otherwise.

Core Commands
Commandstdin PDFstdout PDFNotes
validateyesnoReads one or more input PDFs; - may appear as an input file.
optimizeyesyesUse pdfcpu optimize - - for a full PDF pipe.
infoyesnoSupports text and JSON info output for streamed input.
mergepartialyesmerge create mode accepts one stdin input; stdout is supported for create and zip mode, not append mode.
splityesnoWrites split PDFs into outDir.
collectyesyesCreates a selected page sequence.
trimyesyesWrites a processed PDF.
rotateyesyesWrites a processed PDF.
cropyesyesWrites a processed PDF.
resizeyesyesWrites a processed PDF.
zoomyesyesWrites a processed PDF.
stamp add/update/removeyesyesStamp source files remain regular file arguments.
watermark add/update/removeyesyesWatermark source files remain regular file arguments.
signatures validateyesnoValidation output is text.
signatures removeyesyesWrites a processed PDF.
Security Commands
Commandstdin PDFstdout PDFNotes
encryptyesyesWrites encrypted PDF output.
decryptyesyesWrites decrypted PDF output.
changeupwyesyesWrites a processed PDF.
changeopwyesyesWrites a processed PDF.
permissions listyesnoOutput is text.
permissions setyesyesWrites a processed PDF.
Page And Document Metadata Commands
Commandstdin PDFstdout PDFNotes
pages insertyesyesWrites a processed PDF.
pages removeyesyesWrites a processed PDF.
boxes listyesnoOutput is text.
boxes add/removeyesyesWrites a processed PDF.
annotations listyesnoOutput is text.
annotations removeyesyesWrites a processed PDF.
bookmarks listyesnoOutput is text.
bookmarks exportyesnoWrites JSON to outFileJSON, not stdout.
bookmarks import/removeyesyesJSON import file remains a regular file argument.
keywords listyesnoOutput is text.
keywords add/removeyesyesWrites a processed PDF.
properties listyesnoOutput is text.
properties add/removeyesyesWrites a processed PDF.
pagelayout listyesnoOutput is text.
pagelayout set/resetyesyesWrites a processed PDF.
pagemode listyesnoOutput is text.
pagemode set/resetyesyesWrites a processed PDF.
viewerpref listyesnoSupports text and JSON output for streamed input.
viewerpref set/resetyesyesJSON input files remain regular file arguments.
Generate And Extract Commands
Commandstdin PDFstdout PDFNotes
createyesyesJSON input file remains a regular file argument.
importn/ayesAccepts one image from stdin as imageFile; writes PDF output to stdout.
bookletyesyesPDF input supports stdin; image inputs remain regular file arguments.
nupyesyesPDF input supports stdin; image inputs remain regular file arguments.
gridyesyesPDF input supports stdin; image inputs remain regular file arguments.
posteryesnoWrites tile PDFs into outDir.
ndownyesnoWrites tile PDFs into outDir.
cutyesnoWrites tile PDFs into outDir.
extract image/font/content/metayesnoWrites extracted files into outDir.
extract pageyespartialUse outDir as - only with one selected page.
images listyesnoOutput is text.
images extractyesnoWrites extracted images into outDir.
images updateyesyesReplacement image file remains a regular file argument.
Forms And Embedded Files
Commandstdin PDFstdout PDFNotes
form listyesnoOutput is text.
form exportyesnoWrites JSON to outFileJSON, not stdout.
form fillyesyesJSON data file remains a regular file argument.
form lock/unlock/reset/removeyesyesWrites a processed PDF.
form multifillyespartialstdout requires --mode merge; outDir is still used for generated instances.
attachments listyesnoOutput is text.
attachments add/removeyesyesAdded/removed files remain regular file arguments.
attachments extractyesnoWrites extracted files into outDir.
portfolio listyesnoOutput is text.
portfolio add/removeyesyesAdded/removed files remain regular file arguments.
portfolio extractyesnoWrites extracted entries into outDir.

Examples

Validate a PDF streamed from S3:

aws s3 cp s3://acme-invoices/invoice.pdf - \
   | pdfcpu validate -

Optimize a PDF without writing an intermediate local file:

aws s3 cp s3://acme-contracts/master.pdf - \
   | pdfcpu optimize - - \
   | aws s3 cp - s3://acme-contracts/optimized/master.pdf

Merge local PDFs and upload the merged PDF:

pdfcpu merge - quarterly/*.pdf \
   | aws s3 cp - s3://acme-reports/quarterly/merged.pdf

Read one merge input from S3:

aws s3 cp s3://acme-reports/cover.pdf - \
   | pdfcpu merge - - chapter1.pdf chapter2.pdf \
   | aws s3 cp - s3://acme-reports/book.pdf

Extract a single page and upload it:

aws s3 cp s3://acme-archive/contract.pdf - \
   | pdfcpu extract --mode page --pages 3 - - \
   | aws s3 cp - s3://acme-archive/pages/contract-page-3.pdf

Run a stateless Kubernetes job that trims and rotates a PDF:

aws s3 cp "$INPUT_URI" - \
   | pdfcpu trim --pages "$PAGES" - - \
   | pdfcpu rotate - "$ROTATION" - \
   | aws s3 cp - "$OUTPUT_URI"