Chapter 9
Multipage Facilities

cpdf -pad-before in.pdf [<range>] [-pad-with pad.pdf] -o out.pdf

cpdf -pad-after in.pdf [<range>] [-pad-with pad.pdf] -o out.pdf

cpdf -pad-every [<integer>] in.pdf [-pad-with pad.pdf] -o out.pdf

cpdf -pad-multiple [<integer>] in.pdf -o out.pdf

cpdf -pad-multiple-before [<integer>] in.pdf -o out.pdf

cpdf [-impose <pagesize> | impose-xy <x y>]
     [-impose-columns] [-impose-rtl] [-impose-btt]
     [-impose-margin <margin>] [-impose-spacing <spacing>]
     [-impose-linewidth <width>] [-fast]
     in.pdf -o out.pdf

cpdf -twoup-stack [-fast] in.pdf -o out.pdf

cpdf -twoup [-fast] in.pdf -o out.pdf

9.1 Inserting Blank Pages

Sometimes, for instance to get a printing arrangement right, it’s useful to be able to insert blank pages into a PDF file. cpdf can add blank pages before a given page or pages, or after. The pages in question are specified by a range in the usual way:

cpdf -pad-before in.pdf 1 -o out.pdf

Add a blank page before page 1 (i.e. at the beginning of the document.)

cpdf -pad-after in.pdf 2,16,38,84,121,147 -o out.pdf

Add a blank page after pages 2, 16, 38, 84, 121 and 147 (for instance, to add a clean page between chapters of a document.)

The dimensions of the padded page are derived from the boxes (media box, crop box etc.) of the page after or before which the padding is to be applied.

The -pad-every n operation places a blank page after every n pages, excluding any last one. For example…

cpdf -pad-every 3 in.pdf -o out.pdf

Add a blank page after every three pages

…on a 9 page document adds a blank page after pages 3 and 6.

In all three of these operations, one may specify -pad-with providing a (usually one-page) PDF file to be used instead of a blank page. For example, a page saying “This page left intentionally blank”.

The -pad-multiple n operation adds blank pages so the document has a multiple of n pages. For example:

cpdf -pad-multiple 8 in.pdf -o out.pdf

Add blank pages to in.pdf so it has a multiple of 8 pages.

The -pad-multiple-before n operation adds the padding pages at the beginning of the file instead.

9.2 Imposition

Imposition is the act of putting two or more pages of an input document onto each page of the output document. There are two operations provided by cpdf:

cpdf -impose a0landscape in.pdf -o out.pdf

Impose as many pages as will fit on to new A0 landscape pages.

cpdf -impose-xy "3 4" in.pdf -o out.pdf

Impose 3 across and 4 down on to new pages of 3 times the width and 4 times the height of the input ones.

The x value for -impose-xy may be set to zero to indicate an infinitely-wide page; the y value to indicate an infinitely-long one.

In both cases, the pages in the input file are assumed to be of the same dimensions.

The following options may be used to modify the output:

To impose with rotated pages, for example to put two A4 portrait pages two-up on an A3 landscape page, rotate them prior to imposition.

Two other ways of putting multiple pages on a single page remain from earlier versions of cpdf which lacked a general imposition operation. The -twoup-stack operation puts two logical pages on each physical page, rotating them 90 degrees to do so. The new mediabox is thus larger. The -twoup operation does the same, but scales the new sides down so that the media box is unchanged.

cpdf -two-up in.pdf -o out.pdf

Impose a document two-up, keeping the existing page size.

cpdf -two-up-stack in.pdf -o out.pdf

Impose a document two-up on a larger page by rotation.

NB: For all imposition options, see also discussion of -fast in Section 1.13.

Java Interface

 
/* CHAPTER 9. Multipage facilities */ 
 
/** Imposes a PDF. 
@param pdf PDF document 
@param x x parameter 
@param y y parameter 
@param fit <code>true</code>: impose to fit a page of size x by y; 
<code>false</code>: impose x by y 
@param columns imposes by columns rather than rows 
@param rtl impose right-to-left 
@param btt impose bottom-to-top 
@param center unused for now 
@param margin margin around the output 
@param spacing spacing between imposed inputs */ 
public native void impose(Pdf pdf, double x, double y, boolean fit, 
                          boolean columns, boolean rtl, boolean btt, 
                          boolean center, double margin, double spacing, 
                          double linewidth) 
    throws CpdfError; 
 
/** Imposes a document two up. twoUp does so by shrinking the page size, to 
fit two pages on one. */ 
public native void twoUp(Pdf pdf) throws CpdfError; 
 
/** Imposes a document two up. twoUpStack does so by doubling the page 
size, to fit two pages on one. */ 
public native void twoUpStack(Pdf pdf) throws CpdfError; 
 
/** Adds a blank page before each page in the given range. */ 
public native void padBefore(Pdf pdf, Range range) throws CpdfError; 
 
/** Adds a blank page after each page in the given range. */ 
public native void padAfter(Pdf pdf, Range range) throws CpdfError; 
 
/** Adds a blank page after every n pages. */ 
public native void padEvery(Pdf pdf, int n) throws CpdfError; 
 
/** Adds pages at the end to pad the file to a multiple of n pages in 
length. */ 
public native void padMultiple(Pdf pdf, int n) throws CpdfError; 
 
/** Adds pages at the beginning to pad the file to a multiple of n pages in 
length. */ 
public native void padMultipleBefore(Pdf pdf, int n) throws CpdfError;