Skip to content
Browse files


  • Loading branch information...
hhrutter committed Mar 14, 2019
1 parent 967c250 commit ca95cee228a9837387adb72813f5df5652ec53b8
Showing with 3 additions and 131 deletions.
  1. +3 −131
@@ -13,106 +13,11 @@ It provides both an API and a CLI. Supported are all versions up to PDF 1.7 (ISO

## Status

Version: 0.1.21
[Version: 0.1.21](

Fixes: #51, #58
## Demo Screencast

This release features two new commands:

* N-up
* Grid

The *N-up* command rearranges the pages of a PDF file in order to reduce its page count.<br>
This is achieved by rendering the input pages onto a grid which dimensions are defined by the supplied [N-up]( value (2, 3, 4, 6, 8, 9, 12, 16).<br>
Supported are various n-Up orientations: rd(right,down)=default, dr(down,right), ld(left,down), dl(down,left)<br>
Proper rotation based on involved aspect ratios will be applied during the process.

`pdfcpu nup out.pdf 4 in.pdf` produces a PDF-file where each page fits 4 original pages into a 2x2 grid:<br>

<p align="center">
<img border="2" src="resources/nup4pdf.png" height="200">

The output file will use the page size of the input file unless explicitly declared by a description string like so:<br>
`pdfcpu nup 'f:A4' out.pdf 9 in.pdf`<br>

<p align="center">
<img border="2" src="resources/nup9pdf.png" width="145">

Please refer to `pdfcpu help paper` for a list of supported paper formats.
Most well known paper size standards are supported.

`nup` also accepts a list of image files with the result of rendering all images
in N-up fashion into a PDF file using the specified paper size (default=A4):<br>

`pdfcpu nup 'f:A4L' out.pdf 4 *.jpg *.png *.tif`<br>
generates a PDF file using *A4 Landscape* where each page fits 4 images onto a 2x2 grid.
Grid border lines are rendered by default:
<p align="center">
<img border="2" src="resources/nup4img.png" height="200">

A single image input file will produce a single page PDF with the image N-up'ed accordingly, eg.<br>
`pdfcpu nup 'f:Ledger, b:off, m:0' out.pdf 16 logo.jpg`<br>
Both grid borders and margins are suppressed in this example and the output format is *Ledger*:
<p align="center">
<img border="2" src="resources/nup16img.png" height="200">

The *grid* command rearranges the pages of a PDF file for enhanced reading experience.
The page size of the output file is a grid of specified dimensions in original page units.
Pages may be big but that's ok since they are not supposed to be printed. One use case mentioned by the
community was to produce PDF files for source code listings eg. in the form of 10x1 grid pages:

`pdfcpu grid 'b:off' out.pdf 1 4 in.pdf`<br>
rearranges pages of in.pdf into 1x4 grids and writes the result to out.pdf using the default orientation.<br>
The output page size is the result of a 1(hor)x4(vert) page grid using in.pdf's page size:
<p align="center">
<img border="1" src="resources/gridpdf.png" height="200">

When applied to image files this command produces photo galleries of arbitrary dimensions in PDF form.<br>
`pdfcpu grid 'd:500 500, m:20, b:off' out.pdf 5 2 *.jpg`<br>
arranges imagefiles onto a 5x2 page grid and writes the result to out.pdf using a grid cell size of 500x500:
<p align="center">
<img border="1" src="resources/gridimg.png" height="200">

## Motivation

This is an effort to build a PDF processing library from the ground up written in Go with strong support for batch processing via a rich command line. Over time `pdfcpu` aims to support the standard range of PDF processing features and also any interesting use cases that may present themselves along the way.

One example is reducing the size of large PDF files for mass mailings by optimization to the bare minimum. This can be achieved by analyzing a PDF's cross reference table, removing redundant embedded resources like font files or images and by always writing back the file maxing out PDF compression. I also wanted to have my own swiss army knife for PDFs written entirely in [Go]( that allows me to trim, split, stamp and merge PDF content.

## Features

* Validate (validates PDF files up to version 7.0)
* Read (builds xref table from PDF file)
* Write (writes xref table to PDF file)
* Optimize (gets rid of redundancies like duplicate fonts, images)
* Split (split multi-page PDF into several PDFs according to split span)
* Merge (a set of PDF files into one consolidated PDF file)
* Extract Images (extract all embedded images of a PDF file into a given dir)
* Extract Fonts (extract all embedded fonts of a PDF file into a given dir)
* Extract Pages (extract specific pages into a given dir)
* Extract Content (extract the PDF-Source into given dir)
* Extract Metadata (extract XML metadata)
* Trim (generate a custom version of a PDF file including selected pages)
* Stamp/Watermark selected pages with text, image or PDF page
* Import convert/import images into PDF
* N-up (rearrange pages/images into grid page layout for reduced number of pages)
* Grid (rearrange pages/images into grid page layout for enhanced browsing experience)
* Rotate selected pages
* Manage (add,remove,list,extract) embedded file attachments
* Encrypt (sets password protection)
* Decrypt (removes password protection)
* Change user/owner password
* Manage (add,list) user access permissions

## Demo Screencast (this is an older version with a smaller command set)
(using older version with a smaller command set)


@@ -122,39 +27,6 @@ Required build version: go1.9 and up

`go get`

## Usage

pdfcpu validate [-verbose] [-mode strict|relaxed] [-upw userpw] [-opw ownerpw] inFile
pdfcpu optimize [-verbose] [-stats csvFile] [-upw userpw] [-opw ownerpw] inFile [outFile]
pdfcpu split [-verbose] [-upw userpw] [-opw ownerpw] inFile outDir [span]
pdfcpu merge [-verbose] outFile inFile...
pdfcpu extract [-verbose] -mode image|font|content|page|meta [-pages pageSelection] [-upw userpw] [-opw ownerpw] inFile outDir
pdfcpu trim [-verbose] -pages pageSelection [-upw userpw] [-opw ownerpw] inFile outFile

pdfcpu stamp [-verbose] -pages pageSelection description inFile [outFile]
pdfcpu watermark [-verbose] -pages pageSelection description inFile [outFile]
pdfcpu import [-v(erbose)|vv] [description] outFile imageFile...
pdfcpu nup [-v(erbose)|vv] [-pages pageSelection] [description] outFile n inFile|imageFiles...
pdfcpu grid [-v(erbose)|vv] [-pages pageSelection] [description] outFile m n inFile|imageFiles...
pdfcpu rotate [-v(erbose)|vv] [-pages pageSelection] inFile rotation

pdfcpu attach list [-verbose] [-upw userpw] [-opw ownerpw] inFile
pdfcpu attach add [-verbose] [-upw userpw] [-opw ownerpw] inFile file...
pdfcpu attach remove [-verbose] [-upw userpw] [-opw ownerpw] inFile [file...]
pdfcpu attach extract [-verbose] [-upw userpw] [-opw ownerpw] inFile outDir [file...]

pdfcpu encrypt [-verbose] [-mode rc4|aes] [-key 40|128] [-perm none|all] [-upw userpw] [-opw ownerpw] inFile [outFile]
pdfcpu decrypt [-verbose] [-upw userpw] [-opw ownerpw] inFile [outFile]
pdfcpu changeupw [-verbose] [-opw ownerpw] inFile upwOld upwNew
pdfcpu changeopw [-verbose] [-upw userpw] inFile opwOld opwNew

pdfcpu perm list [-verbose] [-upw userpw] [-opw ownerpw] inFile
pdfcpu perm add [-verbose] [-perm none|all] [-upw userpw] -opw ownerpw inFile

pdfcpu version

[Please read the documentation](

## Contributing

### What

0 comments on commit ca95cee

Please sign in to comment.
You can’t perform that action at this time.