Skip to contents

pdf_pdfxup() creates an n-up pdf using the pdfxup command-line program. pdf_pdfxup_booklet() is a convenience wrapper around pdf_pdfxup() with opinionated defaults better suited for printing a physical booklet on a home printer. pdfxup computes the bounding box of the input to remove margins, keeping text readable.

Usage

pdf_pdfxup(
  input,
  output = NULL,
  ...,
  ncol = 2L,
  nrow = 1L,
  byrow = TRUE,
  booklet = FALSE,
  orientation = "landscape",
  paper = getOption("papersize", "letter"),
  margins = unit(5, "pt"),
  intspaces = unit(1, "pt"),
  innermargins = unit(5, "pt"),
  framewidth = ifelse(isFALSE(booklet), unit(0.4, "pt"), unit(0, "pt")),
  default.units = "pt",
  clip = TRUE,
  pages = "all",
  bb_pages = "all"
)

pdf_pdfxup_booklet(
  input,
  output = NULL,
  ...,
  booklet = "se",
  margins = unit(0.375, "in"),
  intspaces = unit(0.1875, "in"),
  innermargins = unit(0, "pt")
)

Arguments

input

Input pdf filename.

output

Output pdf filename. NULL defaults to tempfile(fileext = ".pdf").

...

Ignored.

ncol, nrow

Number of columns/rows per page.

byrow

If TRUE fill pages row by row. If FALSE fill pages column by column.

booklet

If TRUE configure for printing as a 2-up booklet. Can also be "se" (short-edge mode) or "le" (long-edge mode) for explicit control over two-sided printing; booklet = TRUE defaults to "le" mode.

orientation

Either "landscape" or "portrait".

paper

Paper size (e.g. "letter" or "a4"). The name must be known by the LaTeX geometry package.

margins

Margin of pages of the new document as a grid::unit() object.

intspaces

Space between pages as a grid::unit() object.

innermargins

Inner margin between frame and page as a grid::unit() object.

framewidth

Width of the frame around each page as a grid::unit() object.

default.units

Default units when a numeric value is passed for margins, intspaces, innermargins, or framewidth.

clip

If TRUE clip pages to the computed bounding box.

pages

A positive numeric vector of pages to include, a negative numeric vector of pages to exclude, or a string:

all

Include all the pages.

even

Include just the even pages.

odd

Include just the odd pages.

The functions pdf_pages() and pdf_subset() also support the string:

2-up saddle stitch

The order of the pages to create a saddle-stitch booklet if printing 2-up.

interleave

Interleave the first and second halves of the pages. Requires an even number of pages.

interleave_first

Repeat the first page n - 1 times and interleave with the remaining n - 1 pages.

interleave_last

Repeat the last page n - 1 times and interleave with the first n - 1 pages.

bb_pages

Pages to use when computing the bounding box (see pages argument for supported values). Defaults to "all". Note negative numbers indicate pages to omit from computation of bounding box.

Value

output pdf file name invisibly. As a side effect creates an n-up pdf.

Details

pdf_pdfxup() tries to closely follow the pdfxup defaults. In contrast pdf_pdfxup_booklet() makes these alternative defaults:

  • booklet = "se" which I find easier to reason about than "le"

  • margins = unit(3/8, "in") to provide adequate margins for home printers

  • intspaces = unit(3/16, "in") to provide adequate gutter space for folding

  • innermargins = unit(0, "pt")

See also

https://ctan.org/tex-archive/support/pdfxup for more information about pdfxup

Examples

f1 <- system.file("doc", "Sweave.pdf", package = "utils")
if (nzchar(Sys.which("pdfxup")) && file.exists(f1)) {
  f2 <- pdf_pdfxup_booklet(f1)
  unlink(f2)
}