| Title: | Utilities for Print-and-Play Board Games |
|---|---|
| Description: | Functions for creating and editing PDF files for print-and-play board games with a consistent interface in which the input filename is the first argument, the output filename is the second, and all other arguments are named. Includes functions to resize, scale, rotate, and combine PDF pages, add crop marks, crosshairs, and origami fold guides, and create plastic storage box jackets and origami card wallets. Also provides layout functions for splitting pages into individual component images and reassembling them. Wraps PDF functionality from 'qpdf', 'pdftools', and 'xmpdf' and optionally uses 'ghostscript', 'pdfxup', and 'bittermelon' for additional functionality. |
| Authors: | Trevor L. Davis [aut, cre] (ORCID: <https://orcid.org/0000-0001-6341-4639>) |
| Maintainer: | Trevor L. Davis <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.0-21 |
| Built: | 2026-05-11 06:38:04 UTC |
| Source: | https://github.com/trevorld/pnpmisc |
bm_create_pdf() creates a pdf from a list of images (each representing a page).
bm_create_pdf( pages, output = NULL, ..., paper = getOption("papersize", "letter"), orientation = c("portrait", "landscape"), width = 8.5, height = 11, bg = "white" )bm_create_pdf( pages, output = NULL, ..., paper = getOption("papersize", "letter"), orientation = c("portrait", "landscape"), width = 8.5, height = 11, bg = "white" )
pages |
A list of images (each representing a page). |
output |
Output pdf filename. |
... |
Ignored. |
paper |
Paper size. Usually either "letter" or "a4" but in certain circumstances can be one of "letter", "a4", "poker", "bridge", "legal", "a5", "a3", "special". |
orientation |
Either "portrait" or "landscape". Ignored if |
width, height
|
Paper size in inches. Ignored if both are missing (in favor of |
bg |
|
output pdf file name invisibly.
As a side effect creates a blank pdf file.
f1 <- pdf_create_blank(paper = "a4", orientation = "landscape") f2 <- pdf_create_blank(length = 4L) unlink(f1) unlink(f2)f1 <- pdf_create_blank(paper = "a4", orientation = "landscape") f2 <- pdf_create_blank(length = 4L) unlink(f1) unlink(f2)
bm_crop_layout() crops out a print-and-play component from a layout.
bm_crop_layout( page, ..., layout = "button_shy_cards", row = 1L, col = 1L, bleed = FALSE, name = NULL )bm_crop_layout( page, ..., layout = "button_shy_cards", row = 1L, col = 1L, bleed = FALSE, name = NULL )
page |
A |
... |
Ignored for now. |
layout |
Either a layout preset name in |
row, col
|
The |
bleed |
Include the bleed (if available). |
name |
Instead of |
A bittermelon::bm_pixmap() object.
bm_split_layout() to extract all components from the layout
## Not run: # User not expected to have this PDF file if (requireNamespace("bittermelon", quietly = TRUE)) { input <- "A Nice Cuppa - PNP.pdf" page <- pdf_render_bm_pixmap(input, page = 4L, dpi = 75) card <- bm_crop_layout(page, layout = "button_shy_cards", row = 1L, col = 1L) grid::grid.raster(card) } ## End(Not run)## Not run: # User not expected to have this PDF file if (requireNamespace("bittermelon", quietly = TRUE)) { input <- "A Nice Cuppa - PNP.pdf" page <- pdf_render_bm_pixmap(input, page = 4L, dpi = 75) card <- bm_crop_layout(page, layout = "button_shy_cards", row = 1L, col = 1L) grid::grid.raster(card) } ## End(Not run)
bm_rm_crosshairs() removes crosshairs from a raster object.
bm_rm_crosshairs(x, ..., layout = "poker_3x2_bleed")bm_rm_crosshairs(x, ..., layout = "poker_3x2_bleed")
x |
A raster object coercible to a |
... |
Ignored for now. |
layout |
Either a layout preset name in |
In order to work the PnP layout needs a solid color bleed.
The default layout supports Galdor's Grip (PnP letter size v1).
A bittermelon::bm_pixmap() object.
pdf_rm_crosshairs() to remove crosshairs from a pdf.
if (requireNamespace("bittermelon", quietly = TRUE) && requireNamespace("piecepackr", quietly = TRUE) && utils::packageVersion("piecepackr") >= "1.14.0-5") { f1 <- pdf_create_blank(length = 1L, width = 11, height = 8.5) f2 <- pdf_add_crosshairs(f1, pages = "all", layout = "poker_3x2_bleed") page <- pdf_render_bm_pixmap(f2, page = 1L, dpi = 75) page2 <- bm_rm_crosshairs(page, layout = "poker_3x2_bleed") unlink(f1) unlink(f2) }if (requireNamespace("bittermelon", quietly = TRUE) && requireNamespace("piecepackr", quietly = TRUE) && utils::packageVersion("piecepackr") >= "1.14.0-5") { f1 <- pdf_create_blank(length = 1L, width = 11, height = 8.5) f2 <- pdf_add_crosshairs(f1, pages = "all", layout = "poker_3x2_bleed") page <- pdf_render_bm_pixmap(f2, page = 1L, dpi = 75) page2 <- bm_rm_crosshairs(page, layout = "poker_3x2_bleed") unlink(f1) unlink(f2) }
bm_split_layout() extracts print-and-play components from a layout.
bm_split_layout(page, ..., layout = "button_shy_cards", bleed = FALSE)bm_split_layout(page, ..., layout = "button_shy_cards", bleed = FALSE)
page |
A |
... |
Ignored for now. |
layout |
Either a layout preset name in |
bleed |
Include the bleed (if available). |
A bittermelon::bm_list() of bittermelon::bm_pixmap() objects.
bm_crop_layout() to just crop a single component
## Not run: # User not expected to have this PDF file if (requireNamespace("bittermelon", quietly = TRUE)) { input <- "A Nice Cuppa - PNP.pdf" page <- pdf_render_bm_pixmap(input, page = 4L, dpi = 75) cards <- bm_split_layout(page, layout = "button_shy_cards") grid::grid.raster(cards[[1L]]) } ## End(Not run)## Not run: # User not expected to have this PDF file if (requireNamespace("bittermelon", quietly = TRUE)) { input <- "A Nice Cuppa - PNP.pdf" page <- pdf_render_bm_pixmap(input, page = 4L, dpi = 75) cards <- bm_split_layout(page, layout = "button_shy_cards") grid::grid.raster(cards[[1L]]) } ## End(Not run)
fullGrob() is a wrapper around grid::rectGrob() for a single
rectangle grob filled with a color, bitmap, grob, or pattern.
In particular grob or bitmap fills will be automatically converted to a grid::pattern() fill by as_fill().
grid.full() creates a fullGrob() and draws it to the screen.
fullGrob( fill = "transparent", ..., width = NULL, height = NULL, vp = NULL, name = NULL ) grid.full(...) as_fill(fill = "transparent", ..., width = NULL, height = NULL)fullGrob( fill = "transparent", ..., width = NULL, height = NULL, vp = NULL, name = NULL ) grid.full(...) as_fill(fill = "transparent", ..., width = NULL, height = NULL)
fill |
A color string, a |
... |
Ignored for now. |
width, height
|
If |
vp, name
|
Passed to |
fullGrob() and grid.full() return grid::rectGrob() object.
As a side effect grid.full() draws to the active graphics device. as_fill() returns a supported grid fill object such as a color string or a grid::pattern() object.
grob <- fullGrob(grid::radialGradient()) grid::grid.draw(grob)grob <- fullGrob(grid::radialGradient()) grid::grid.draw(grob)
grid_add_cropmarks() adds crop marks to the edges of components of a print-and-play layout.
grid_add_cropmarks( ..., layout = "poker_3x3", bleed = NULL, gp = gpar(), cm_width = unit(0.25, "mm"), cm_length = unit(0.125, "in") )grid_add_cropmarks( ..., layout = "poker_3x3", bleed = NULL, gp = gpar(), cm_width = unit(0.25, "mm"), cm_length = unit(0.125, "in") )
... |
Passed to |
layout |
Either a layout preset name in |
bleed |
Passed to |
gp, cm_width, cm_length
|
Passed to |
This function draws in inches so make sure your graphics device is "big" enough.
NULL invisibly.
As a side effect draws crop marks to the active graphics device.
pdf_add_cropmarks(), piecepackr::grid.cropmark()
if (requireNamespace("piecepackr", quietly = TRUE) && utils::packageVersion("piecepackr") >= "1.14.0-6") { grid::grid.newpage() vp <- grid::viewport(width=8.5, height=11, default.units="in", x=0.5, y=0.5, just=c("left", "bottom")) grid::pushViewport(vp) grid_add_rects(layout = "poker_3x3") grid_add_cropmarks(layout = "poker_3x3") grid::popViewport() }if (requireNamespace("piecepackr", quietly = TRUE) && utils::packageVersion("piecepackr") >= "1.14.0-6") { grid::grid.newpage() vp <- grid::viewport(width=8.5, height=11, default.units="in", x=0.5, y=0.5, just=c("left", "bottom")) grid::pushViewport(vp) grid_add_rects(layout = "poker_3x3") grid_add_cropmarks(layout = "poker_3x3") grid::popViewport() }
grid_add_crosshairs() draws crosshairs at the corners of components of a print-and-play layout.
grid_add_crosshairs( ..., layout = "poker_3x3", gp = gpar(), ch_width = unit(1/6, "in"), ch_grob = NULL )grid_add_crosshairs( ..., layout = "poker_3x3", gp = gpar(), ch_width = unit(1/6, "in"), ch_grob = NULL )
... |
Passed to |
layout |
Either a layout preset name in |
gp, ch_width, ch_grob
|
Passed to |
This function draws in inches so make sure your graphics device is "big" enough.
NULL invisibly.
As a side effect draws crosshairs to the active graphics device.
if (requireNamespace("piecepackr", quietly = TRUE) && utils::packageVersion("piecepackr") >= "1.14.0-5") { grid::grid.newpage() vp <- grid::viewport(width=8.5, height=11, default.units="in", x=0.5, y=0.5, just=c("left", "bottom")) grid::pushViewport(vp) grid_add_crosshairs(layout = "poker_3x3") grid::popViewport() }if (requireNamespace("piecepackr", quietly = TRUE) && utils::packageVersion("piecepackr") >= "1.14.0-5") { grid::grid.newpage() vp <- grid::viewport(width=8.5, height=11, default.units="in", x=0.5, y=0.5, just=c("left", "bottom")) grid::pushViewport(vp) grid_add_crosshairs(layout = "poker_3x3") grid::popViewport() }
grid_add_layout() draws images to a layout in grid.
grid_add_layout(images, ..., layout = "poker_3x3")grid_add_layout(images, ..., layout = "poker_3x3")
images |
A named list of images with all the names in the |
... |
Ignored for now. |
layout |
Either a layout preset name in |
NULL invisibly.
As a side effect draws images to the active graphics device.
piecepackr::pmap_piece() to draw pieces to a layout represented by a piecepackr::pp_cfg() object.
if (requireNamespace("bittermelon", quietly = TRUE)) { crops <- bittermelon::farming_crops_16x16()$corn layout <- data.frame( name = names(crops), x = 0.1 + rep(c(1, 3, 5), 2), y = 0.1 + rep(c(3, 1), each = 3), width = 2, height = 2, angle = 0 ) grid::grid.newpage() grid_add_layout(crops, layout = layout) grid_add_rects(layout = layout, gp = grid::gpar(lwd = 4)) }if (requireNamespace("bittermelon", quietly = TRUE)) { crops <- bittermelon::farming_crops_16x16()$corn layout <- data.frame( name = names(crops), x = 0.1 + rep(c(1, 3, 5), 2), y = 0.1 + rep(c(3, 1), each = 3), width = 2, height = 2, angle = 0 ) grid::grid.newpage() grid_add_layout(crops, layout = layout) grid_add_rects(layout = layout, gp = grid::gpar(lwd = 4)) }
grid_add_lines() draws lines along the components of a print-and-play layout.
grid_add_lines(..., layout = "poker_3x3", gp = gpar())grid_add_lines(..., layout = "poker_3x3", gp = gpar())
... |
Ignored for now. |
layout |
Either a layout preset name in |
gp |
Passed to |
This function draws in inches so make sure your graphics device is "big" enough.
NULL invisibly.
As a side effect draws lines to the active graphics device.
grid::grid.newpage() vp <- grid::viewport(width=8.5, height=11, default.units="in", x=0.0, y=0.0, just=c("left", "bottom")) grid::pushViewport(vp) grid_add_lines(layout = "poker_3x3", gp = grid::gpar(lty = "dashed", col = "grey")) grid::popViewport()grid::grid.newpage() vp <- grid::viewport(width=8.5, height=11, default.units="in", x=0.0, y=0.0, just=c("left", "bottom")) grid::pushViewport(vp) grid_add_lines(layout = "poker_3x3", gp = grid::gpar(lty = "dashed", col = "grey")) grid::popViewport()
grid_add_origami() draws origami fold symbols for a box jacket.
grid_add_origami_bb() draws origami fold symbols optimized for
Boardgame Barrio's Small Board Game Jackets.
grid_add_origami_bb() grid_add_origami( ..., xc = unit(0.5, "npc"), yc = unit(0.5, "npc"), width = unit(JACKET_4x6_FRONT_WIDTH, "inches"), height = unit(JACKET_4x6_HEIGHT, "inches"), depth = unit(JACKET_4x6_SPINE_WIDTH, "inches") )grid_add_origami_bb() grid_add_origami( ..., xc = unit(0.5, "npc"), yc = unit(0.5, "npc"), width = unit(JACKET_4x6_FRONT_WIDTH, "inches"), height = unit(JACKET_4x6_HEIGHT, "inches"), depth = unit(JACKET_4x6_SPINE_WIDTH, "inches") )
... |
Ignored. |
xc, yc
|
Center of the jacket as |
width |
Front/back panel width as a |
height |
Jacket height as a |
depth |
Spine width as a |
NULL invisibly. As a side effect draws origami fold symbols
on the active graphics device.
grid::grid.newpage() pnpmisc:::grid_add_jacket_outer() grid_add_origami()grid::grid.newpage() pnpmisc:::grid_add_jacket_outer() grid_add_origami()
grid_add_rects() draws (rounded) rectangles around components of a print-and-play layout.
grid_add_rects( ..., layout = "poker_3x3", r = unit(0, "in"), gp = gpar(col = "black", fill = NA, lwd = 1) )grid_add_rects( ..., layout = "poker_3x3", r = unit(0, "in"), gp = gpar(col = "black", fill = NA, lwd = 1) )
... |
Ignored for now. |
layout |
Either a layout preset name in |
r, gp
|
Passed to |
This function draws in inches so make sure your graphics device is "big" enough.
Sometimes if you use the same color as a solid background color this can be used to effectively "remove" unwanted card outlines.
NULL invisibly.
As a side effect draws rectangles to the active graphics device.
pdf_add_rects(), grid::grid.roundrect()
grid::grid.newpage() vp <- grid::viewport(width=8.5, height=11, default.units="in", x=0.5, y=0.5, just=c("left", "bottom")) grid::pushViewport(vp) grid_add_rects(layout = "poker_3x3") grid::popViewport()grid::grid.newpage() vp <- grid::viewport(width=8.5, height=11, default.units="in", x=0.5, y=0.5, just=c("left", "bottom")) grid::pushViewport(vp) grid_add_rects(layout = "poker_3x3") grid::popViewport()
layout_grid() calculates a layout data frame
for a grid of identically sized print-and-play components.
layout_grid( nrow = 2L, ncol = 1L, width = 2.5, height = 3.5, bleed = 0, paper = getOption("papersize", "letter"), orientation = c("landscape", "portrait"), angle = 0, name = layout_name_fn(), direction = "left-to-right" )layout_grid( nrow = 2L, ncol = 1L, width = 2.5, height = 3.5, bleed = 0, paper = getOption("papersize", "letter"), orientation = c("landscape", "portrait"), angle = 0, name = layout_name_fn(), direction = "left-to-right" )
nrow, ncol
|
Number of rows and columns of print-and-play components (e.g. cards) |
width, height, bleed
|
Width, height, and bleed for each print-and-play component (in inches) |
paper, orientation
|
Print-and-play paper size and orientation |
angle |
Vector of angles of the pieces in degrees (counter-clockwise) (assigned |
name |
Either a vector of names of each piece or a function with arguments |
direction |
Should |
A data frame with columns "row", "col", "x", "y", "angle", "width", "height", "bleed", "paper", "orientation", and "name".
# Button Shy card layout layout_grid(nrow = 2L, ncol = 3L, height = 3.447, width = 2.469, bleed = 0.125)# Button Shy card layout layout_grid(nrow = 2L, ncol = 3L, height = 3.447, width = 2.469, bleed = 0.125)
layout_name_fn() returns a function that takes nrow and ncol arguments and generates a character vector of nrow * ncol names. Intended for use with layout_grid().
layout_name_fn(prefix = "piece.", from = 1L, width = 1L, flag = "0")layout_name_fn(prefix = "piece.", from = 1L, width = 1L, flag = "0")
prefix |
Prefix for the generated names. |
from |
Starting number for the generated name suffix. |
width, flag
|
Passed to |
A function with arguments nrow and ncol that would return a character vector of length nrow * ncol.
layout_name_fn()(nrow = 3, ncol = 3) layout_name_fn("back_", from = 97, width = 3L)(nrow = 2, ncol = 3)layout_name_fn()(nrow = 3, ncol = 3) layout_name_fn("back_", from = 97, width = 3L)(nrow = 2, ncol = 3)
layout_preset() calculates a layout data frame
for a named preset.
layout_names() returns the supported layout presets.
layout_preset(preset = "button_shy_cards", ...) layout_names()layout_preset(preset = "button_shy_cards", ...) layout_names()
preset |
Preset name. Must be in |
... |
Passed to |
Unless otherwise indicated assumes letter-sized paper. Supports the following presets:
Button Shy Games PnP cards.
Caveat: matches many but not all of their PnP files e.g. ROVE-PNP-V2.pdf better matches the poker_3x2_bleed layout.
Button Shy Games PnP rule booklet pages (8-page booklet).
Button Shy Games PnP rule booklet pages (4-page booklet).
Poker-sized cards (2.5" by 3.5") in 3 columns of 2 cards (landscape) with an 1/8" bleed around each card. Examples of PnP games using this layout include Galdor's Grip.
Poker-sized cards (2.5" by 3.5") in 3 columns of 3 cards (portrait) with an zero bleed around each card. Examples of PnP games using this layout include the original Mini Rogue.
Poker-sized cards (2.5" by 3.5") in 4 columns of 2 cards (landscape) with zero bleed around each card. Examples of PnP games using this layout include the Decktet.
A single 4x6 photo storage box jacket as created by pdf_create_4x6_jacket(). The width covers the full jacket (back + spine + front).
A single poker deck storage box jacket as created by pdf_create_poker_jacket(). The width covers the full jacket (back + spine + front).
Two poker deck storage box jackets as created by pdf_create_poker_jacket() when passed a list of two items. Uses portrait paper. The bleed column is zero (the gap between jackets is encoded in the y positions).
A data frame with columns "row", "col", "x", "y", "angle", "width", "height", "bleed", "paper", "orientation", and "name".
layout_preset("button_shy_cards") layout_names()layout_preset("button_shy_cards") layout_names()
Using the functions in this package can lead to several pdf
files cluttering your tempdir().
ls_temp_pdfs() lists them while rm_temp_pdfs() removes them.
ls_temp_pdfs(exclude = character()) rm_temp_pdfs(exclude = character())ls_temp_pdfs(exclude = character()) rm_temp_pdfs(exclude = character())
exclude |
A character vector of filenames to exclude. |
ls_temp_pdfs() returns a character vector.
rm_temp_pdfs() returns invisible(NULL).
## Not run: # May delete user pdf files in `tempdir()` f1 <- pdf_create_blank() f2 <- pdf_compress(f1) f3 <- pdf_subset(f2, pages = 1L) ls_temp_pdfs() rm_temp_pdfs() ls_temp_pdfs() ## End(Not run)## Not run: # May delete user pdf files in `tempdir()` f1 <- pdf_create_blank() f2 <- pdf_compress(f1) f3 <- pdf_subset(f2, pages = 1L) ls_temp_pdfs() rm_temp_pdfs() ls_temp_pdfs() ## End(Not run)
pdf_add_cropmarks() adds crop marks to the edges of components of a print-and-play layout.
pdf_add_cropmarks( input, output = NULL, ..., layout = "poker_3x3", gp = gpar(), cm_width = unit(0.25, "mm"), cm_length = unit(0.125, "in") )pdf_add_cropmarks( input, output = NULL, ..., layout = "poker_3x3", gp = gpar(), cm_width = unit(0.25, "mm"), cm_length = unit(0.125, "in") )
input |
Input pdf filename. |
output |
Output pdf filename. |
... |
Passed to |
layout |
Either a layout preset name in |
gp, cm_width, cm_length
|
Passed to |
output pdf file name invisibly.
As a side effect adds crop marks to a pdf.
grid_add_cropmarks(), piecepackr::grid.cropmark()
if (requireNamespace("piecepackr", quietly = TRUE)) { input <- pdf_create_blank(length = 2L, width = 11, height = 8.5) output <- pdf_add_cropmarks(input, pages = "odd", layout = "button_shy_cards") unlink(input) unlink(output) }if (requireNamespace("piecepackr", quietly = TRUE)) { input <- pdf_create_blank(length = 2L, width = 11, height = 8.5) output <- pdf_add_cropmarks(input, pages = "odd", layout = "button_shy_cards") unlink(input) unlink(output) }
pdf_add_crosshairs() adds crosshairs to the corners of components of a print-and-play layout.
pdf_add_crosshairs( input, output = NULL, ..., layout = "button_shy_cards", gp = gpar(), ch_width = unit(1/6, "in"), ch_grob = NULL )pdf_add_crosshairs( input, output = NULL, ..., layout = "button_shy_cards", gp = gpar(), ch_width = unit(1/6, "in"), ch_grob = NULL )
input |
Input pdf filename. |
output |
Output pdf filename. |
... |
Passed to |
layout |
Either a layout preset name in |
gp, ch_width, ch_grob
|
Passed to |
The default layout supports Button Shy games.
output pdf file name invisibly.
As a side effect adds crosshairs to a pdf.
if (requireNamespace("piecepackr", quietly = TRUE) && utils::packageVersion("piecepackr") >= "1.14.0-5") { input <- pdf_create_blank(length = 2L, width = 11, height = 8.5) output <- pdf_add_crosshairs(input, pages = "odd", layout = "button_shy_cards") unlink(input) unlink(output) }if (requireNamespace("piecepackr", quietly = TRUE) && utils::packageVersion("piecepackr") >= "1.14.0-5") { input <- pdf_create_blank(length = 2L, width = 11, height = 8.5) output <- pdf_add_crosshairs(input, pages = "odd", layout = "button_shy_cards") unlink(input) unlink(output) }
pdf_add_lines() adds lines along the components of a print-and-play layout.
pdf_add_lines(input, output = NULL, ..., layout = "poker_3x3", gp = gpar())pdf_add_lines(input, output = NULL, ..., layout = "poker_3x3", gp = gpar())
input |
Input pdf filename. |
output |
Output pdf filename. |
... |
Passed to |
layout |
Either a layout preset name in |
gp |
Passed to |
output pdf file name invisibly.
As a side effect creates pdf file with added line segments.
grid_add_lines(), pdf_add_rects()
f1 <- pdf_create_blank(length = 2L, paper = "letter") f2 <- pdf_add_lines(f1, layout = "poker_3x3") unlink(f1) unlink(f2)f1 <- pdf_create_blank(length = 2L, paper = "letter") f2 <- pdf_add_lines(f1, layout = "poker_3x3") unlink(f1) unlink(f2)
pdf_add_origami() adds origami symbols to the pdf.
Currently only supports adding origami symbols to
Boardgame Barrio's Small Board Game Jackets.
pdf_add_origami(input, output = NULL, ...)pdf_add_origami(input, output = NULL, ...)
input |
Input pdf filename. |
output |
Output pdf filename. |
... |
Passed to |
output pdf file name invisibly.
As a side effect creates pdf file with added origami symbols.
f1 <- pnpmisc:::pdf_create_mock_sbgj() f2 <- pdf_add_origami(f1) unlink(f1) unlink(f2)f1 <- pnpmisc:::pdf_create_mock_sbgj() f2 <- pdf_add_origami(f1) unlink(f1) unlink(f2)
pdf_add_overlay() calls grid_fn on selected pages to draw custom
graphics on top.
pdf_add_overlay(input, output = NULL, ..., grid_fn = grid::grid.null)pdf_add_overlay(input, output = NULL, ..., grid_fn = grid::grid.null)
input |
Input pdf filename. |
output |
Output pdf filename. |
... |
Passed to |
grid_fn |
A zero-argument function called to draw graphics on selected pages.
Defaults to |
output pdf file name invisibly.
As a side effect creates a pdf with overlaid graphics.
pdf_apply() which this function wraps and
pdf_add_cropmarks(), pdf_add_crosshairs(),
pdf_add_lines(), and pdf_add_rects() for specific applications.
pdf_overlay_stamp() alternatively adds the contents of a stamp pdf file.
f1 <- pdf_create_blank(length = 2L, paper = "letter") f2 <- pdf_add_overlay(f1, pages = "all", dpi = 75, grid_fn = function() { grid::grid.text("DRAFT", gp = grid::gpar(col = "red", fontsize = 72, alpha = 0.3)) }) unlink(f1) unlink(f2)f1 <- pdf_create_blank(length = 2L, paper = "letter") f2 <- pdf_add_overlay(f1, pages = "all", dpi = 75, grid_fn = function() { grid::grid.text("DRAFT", gp = grid::gpar(col = "red", fontsize = 72, alpha = 0.3)) }) unlink(f1) unlink(f2)
pdf_add_rects() adds (rounded) rectangles around components of a print-and-play layout.
pdf_add_rects( input, output = NULL, ..., layout = "poker_3x3", r = unit(0, "in"), gp = gpar(col = "black", fill = NA, lwd = 1) )pdf_add_rects( input, output = NULL, ..., layout = "poker_3x3", r = unit(0, "in"), gp = gpar(col = "black", fill = NA, lwd = 1) )
input |
Input pdf filename. |
output |
Output pdf filename. |
... |
Passed to |
layout |
Either a layout preset name in |
r, gp
|
Passed to |
Sometimes if you use the same color as a solid background color this can be used to effectively "remove" unwanted card outlines.
output pdf file name invisibly.
As a side effect creates pdf file with added rectangles.
grid_add_rects(), grid::grid.roundrect(), pdf_add_lines()
f1 <- pdf_create_blank(length = 2L, paper = "letter") f2 <- pdf_add_rects(f1, layout = "poker_3x3") # "Remove" unwanted card border lines by covering up with white f3 <- pdf_add_rects(f2, layout = "poker_3x3", gp = grid::gpar(col = "white", fill = NA, lwd = 2)) unlink(f1) unlink(f2) unlink(f3)f1 <- pdf_create_blank(length = 2L, paper = "letter") f2 <- pdf_add_rects(f1, layout = "poker_3x3") # "Remove" unwanted card border lines by covering up with white f3 <- pdf_add_rects(f2, layout = "poker_3x3", gp = grid::gpar(col = "white", fill = NA, lwd = 2)) unlink(f1) unlink(f2) unlink(f3)
pdf_append_blank() appends blank pages to a pdf.
pdf_append_blank(input, output = NULL, ..., minimum = 1L, multiples_of = 1L)pdf_append_blank(input, output = NULL, ..., minimum = 1L, multiples_of = 1L)
input |
Input pdf filename. |
output |
Output pdf filename. |
... |
Ignored. |
minimum |
Final number of pages should be at least this integer. |
multiples_of |
Final number of pages should be a multiple of this integer. |
f1 <- pdf_create_blank(length = 1L) f2 <- pdf_append_blank(f1, multiples_of = 4L) qpdf::pdf_length(f2) # Clean up unlink(f1) unlink(f2)f1 <- pdf_create_blank(length = 1L) f2 <- pdf_append_blank(f1, multiples_of = 4L) qpdf::pdf_length(f2) # Clean up unlink(f1) unlink(f2)
pdf_apply() renders each page of a pdf as a raster image and
on selected pages additionally calls bm_fn() to modify those raster images
as well as grid_fn overlay custom graphics on top.
pdf_apply( input, output = NULL, ..., pages = "all", rasterize = rasterise, dpi = getOption("pnpmisc.dpi", 300), paper = NULL, bg = "white", scale = 1, bm_fn = identity, grid_fn = grid::grid.null, rasterise = NULL )pdf_apply( input, output = NULL, ..., pages = "all", rasterize = rasterise, dpi = getOption("pnpmisc.dpi", 300), paper = NULL, bg = "white", scale = 1, bm_fn = identity, grid_fn = grid::grid.null, rasterise = NULL )
input |
Input pdf filename. |
output |
Output pdf filename. |
... |
Ignored. |
pages |
A positive numeric vector of pages to include, a negative numeric vector of pages to exclude, or a string:
The functions
|
rasterize, rasterise
|
If
|
dpi |
Dots per inch.
Passed to |
paper |
If |
bg |
|
scale |
A numeric scalar to scale the content by.
Values less than 1 shrink the content within the page; values greater than 1 enlarge it.
By default the original content is not rescaled.
Note this also adjusts the size of the |
bm_fn |
A one-argument function called to edit the selected pages rasterized. The input will be a "raster" object and the output must be an object coercible to a "raster" object by |
grid_fn |
A zero-argument function called to draw graphics on selected pages.
Defaults to |
The original pdf document may be rasterized depending on the value of
bm_fn, pages, paper, scale, and/or rasterize as well as
whether ghostscript is available (see pdf_gs()).
output pdf file name invisibly.
As a side effect creates a pdf with overlaid graphics.
f1 <- pdf_create_blank(length = 2L, paper = "letter", bg = "magenta") if (requireNamespace("bittermelon", quietly = TRUE)) { f2 <- pdf_apply(f1, pages = "even", dpi = 75, bm_fn = bittermelon::bm_invert, grid_fn = function() { grid::grid.text("DRAFT", gp = grid::gpar(col = "red", fontsize = 72, alpha = 0.3)) }) unlink(f2) } unlink(f1)f1 <- pdf_create_blank(length = 2L, paper = "letter", bg = "magenta") if (requireNamespace("bittermelon", quietly = TRUE)) { f2 <- pdf_apply(f1, pages = "even", dpi = 75, bm_fn = bittermelon::bm_invert, grid_fn = function() { grid::grid.text("DRAFT", gp = grid::gpar(col = "red", fontsize = 72, alpha = 0.3)) }) unlink(f2) } unlink(f1)
pdf_change_paper() changes the paper size of a pdf, centering the original
contents on the new paper size.
pdf_pad_paper() is an alias semantically intended for padding an undersized pdf document
to a normal paper size (e.g. padding a pdf smaller than letter to letter size).
pdf_change_paper( input, output = NULL, ..., paper = getOption("papersize", "letter") ) pdf_pad_paper( input, output = NULL, ..., paper = getOption("papersize", "letter") )pdf_change_paper( input, output = NULL, ..., paper = getOption("papersize", "letter") ) pdf_pad_paper( input, output = NULL, ..., paper = getOption("papersize", "letter") )
input |
Input pdf filename. |
output |
Output pdf filename. |
... |
Passed to |
paper |
Paper size. Usually either "letter" or "a4" but in certain circumstances can be one of "letter", "a4", "poker", "bridge", "legal", "a5", "a3", "special". |
By default these function do not scale the original contents
(but you can pass on a scale argument in the ... to pdf_apply()).
output pdf file name invisibly.
As a side effect creates a pdf with the new paper size.
# Some PnP files' size is the intersection of A4/letter page sizes # i.e. shorter than A4 and narrower than letter. # We usually want pad to full A4 or letter page size. input <- tempfile(fileext = ".pdf") grDevices::pdf(input, width = 8.3, height = 11, bg = "blue") grid::grid.text("") invisible(grDevices::dev.off()) pdf_width(input) pdf_height(input) output <- pdf_change_paper(input, paper = "letter") pdf_width(output) pdf_height(output) unlink(output) output_a4 <- pdf_pad_paper(input, paper = "a4") pdf_width(output_a4) pdf_height(output_a4) unlink(output_a4) unlink(input)# Some PnP files' size is the intersection of A4/letter page sizes # i.e. shorter than A4 and narrower than letter. # We usually want pad to full A4 or letter page size. input <- tempfile(fileext = ".pdf") grDevices::pdf(input, width = 8.3, height = 11, bg = "blue") grid::grid.text("") invisible(grDevices::dev.off()) pdf_width(input) pdf_height(input) output <- pdf_change_paper(input, paper = "letter") pdf_width(output) pdf_height(output) unlink(output) output_a4 <- pdf_pad_paper(input, paper = "a4") pdf_width(output_a4) pdf_height(output_a4) unlink(output_a4) unlink(input)
pdf_clean() copies input pdf file to output and removes temporary pdf files with rm_temp_pdfs(exclude = output).
pdf_clean(input, output = NULL, ...)pdf_clean(input, output = NULL, ...)
input |
Input pdf filename. |
output |
Output pdf filename. |
... |
Ignored. |
output pdf file name invisibly.
As a side effect copies input to output and removes temporary pdf files.
## Not run: # May delete user files in `tempdir()` f1 <- pdf_create_blank() f2 <- pdf_compress(f1) f3 <- pdf_subset(f2, pages = 1L) ls_temp_pdfs() pdf_clean(f3, "output.pdf") ls_temp_pdfs() unlink("output.pdf") ## End(Not run)## Not run: # May delete user files in `tempdir()` f1 <- pdf_create_blank() f2 <- pdf_compress(f1) f3 <- pdf_subset(f2, pages = 1L) ls_temp_pdfs() pdf_clean(f3, "output.pdf") ls_temp_pdfs() unlink("output.pdf") ## End(Not run)
qpdf functionsThese functions wrap around the utilities in the qpdf package
but alters the arguments to match this package's conventions:
the first two arguments must be input and output (which by default tempfile(fileext = ".pdf")),
all other arguments must be named,
and any pages argument is first processed by pdf_pages() (so you can also use strings like "even" or "odd").
pdf_combine(input, output = NULL, ...) pdf_compress(input, output = NULL, ...) pdf_overlay_stamp(input, output = NULL, ...) pdf_rotate_pages(input, output = NULL, ..., pages = "all") pdf_subset(input, output = NULL, ..., pages = 1L)pdf_combine(input, output = NULL, ...) pdf_compress(input, output = NULL, ...) pdf_overlay_stamp(input, output = NULL, ...) pdf_rotate_pages(input, output = NULL, ..., pages = "all") pdf_subset(input, output = NULL, ..., pages = 1L)
input |
For |
output |
Output pdf filename. |
... |
Passed to the underlying qpdf functions. |
pages |
A positive numeric vector of pages to include, a negative numeric vector of pages to exclude, or a string:
The functions
|
output filename of new pdf file invisibly.
qpdf::pdf_combine(), qpdf::pdf_compress(),
qpdf::pdf_overlay_stamp(), qpdf::pdf_rotate_pages(), qpdf::pdf_subset()
f1 <- pdf_create_blank(width = 6, height = 4) f2 <- pdf_create_blank(width = 4, height = 6) f3 <- pdf_combine(c(f1, f2)) f4 <- pdf_overlay_stamp(f3, stamp = f1) f5 <- pdf_compress(f4) f6 <- pdf_subset(f5, pages = 1L) f7 <- pdf_rotate_pages(f6, angle = 90) unlink(f1) unlink(f2) unlink(f3) unlink(f4) unlink(f5) unlink(f6) unlink(f7)f1 <- pdf_create_blank(width = 6, height = 4) f2 <- pdf_create_blank(width = 4, height = 6) f3 <- pdf_combine(c(f1, f2)) f4 <- pdf_overlay_stamp(f3, stamp = f1) f5 <- pdf_compress(f4) f6 <- pdf_subset(f5, pages = 1L) f7 <- pdf_rotate_pages(f6, angle = 90) unlink(f1) unlink(f2) unlink(f3) unlink(f4) unlink(f5) unlink(f6) unlink(f7)
pdf_create_blank() creates blank pdf pages.
pdf_create_blank( output = NULL, ..., length = 1L, paper = getOption("papersize", "letter"), orientation = c("portrait", "landscape"), width = 8.5, height = 11, bg = "white", grob = NULL )pdf_create_blank( output = NULL, ..., length = 1L, paper = getOption("papersize", "letter"), orientation = c("portrait", "landscape"), width = 8.5, height = 11, bg = "white", grob = NULL )
output |
Output pdf filename. |
... |
Ignored. |
length |
Number of pages to create. |
paper |
Paper size. Usually either "letter" or "a4" but in certain circumstances can be one of "letter", "a4", "poker", "bridge", "legal", "a5", "a3", "special". |
orientation |
Either "portrait" or "landscape". Ignored if |
width, height
|
Paper size in inches. Ignored if both are missing (in favor of |
bg |
|
grob |
A grid grob to draw on each page
(e.g. |
output pdf file name invisibly.
As a side effect creates a blank pdf file.
f1 <- pdf_create_blank(paper = "a4", orientation = "landscape") f2 <- pdf_create_blank(length = 4L) unlink(f1) unlink(f2)f1 <- pdf_create_blank(paper = "a4", orientation = "landscape") f2 <- pdf_create_blank(length = 4L) unlink(f1) unlink(f2)
pdf_create_jacket() creates a printable storage box jacket.
pdf_create_4x6_jacket() is a wrapper targeting a 4x6 photo storage box.
pdf_create_poker_jacket() is an alternative targeting one or two poker deck storage boxes.
pdf_create_jacket_instructions() creates a printable sheet of
instructions for making such a jacket
(these instructions are repeated in the Details section below).
pdf_create_jacket( output = NULL, ..., front = NULL, back = NULL, spine = NULL, inner = NULL, paper = getOption("papersize", "letter"), orientation = "landscape", width = unit(JACKET_4x6_FRONT_WIDTH, "in"), height = unit(JACKET_4x6_HEIGHT, "in"), depth = unit(JACKET_4x6_SPINE_WIDTH, "in"), bg = "transparent" ) pdf_create_4x6_jacket( output = NULL, ..., front = NULL, back = NULL, spine = NULL, inner = NULL, paper = getOption("papersize", "letter") ) pdf_create_poker_jacket( output = NULL, ..., front = NULL, back = NULL, spine = NULL, inner = NULL, paper = getOption("papersize", "letter"), depth = unit(JACKET_POKER_SPINE_WIDTH, "in"), bg = "transparent" ) pdf_create_jacket_instructions( output = NULL, ..., paper = getOption("papersize", "letter"), orientation = "landscape", style = marquee::classic_style() )pdf_create_jacket( output = NULL, ..., front = NULL, back = NULL, spine = NULL, inner = NULL, paper = getOption("papersize", "letter"), orientation = "landscape", width = unit(JACKET_4x6_FRONT_WIDTH, "in"), height = unit(JACKET_4x6_HEIGHT, "in"), depth = unit(JACKET_4x6_SPINE_WIDTH, "in"), bg = "transparent" ) pdf_create_4x6_jacket( output = NULL, ..., front = NULL, back = NULL, spine = NULL, inner = NULL, paper = getOption("papersize", "letter") ) pdf_create_poker_jacket( output = NULL, ..., front = NULL, back = NULL, spine = NULL, inner = NULL, paper = getOption("papersize", "letter"), depth = unit(JACKET_POKER_SPINE_WIDTH, "in"), bg = "transparent" ) pdf_create_jacket_instructions( output = NULL, ..., paper = getOption("papersize", "letter"), orientation = "landscape", style = marquee::classic_style() )
output |
Output pdf filename. |
... |
Ignored. |
front |
Fill color/pattern/gradient or grob for front cover section of jacket
Will be drawn in a viewport with a
width of |
back |
Fill color/pattern/gradient or grob for back cover section of jacket
Will be drawn in a viewport with a
width of |
spine |
Fill color/pattern/gradient or grob for spine section of jacket
Will be drawn in a rotated viewport with a
width of |
inner |
Fill color/pattern/gradient or grob for inner section of jacket.
Will be drawn in a viewport with a width of |
paper |
Paper size. Usually either "letter" or "a4" but in certain circumstances can be one of "letter", "a4", "poker", "bridge", "legal", "a5", "a3", "special". |
orientation |
Either "portrait" or "landscape". Ignored if |
width |
Width of the jacket face as a grid unit. For a 4x6 photo storage box a good value is 4.139 inches and for a poker deck storage box a good value is 2.6 inches. |
height |
Height of the jacket face as a grid unit. For a 4x6 photo storage box a good value is 6.141 inches and for a poker deck storage box a good value is 3.6 inches. |
depth |
Width of the spine as a grid unit. For a 4x6 photo storage box a good value is 1.052 inches and for a poker deck storage box a good value is 0.78 inches. |
bg |
Background fill for the storage jacket.
Passed to |
style |
A style set such as |
To make the storage box jacket from the pdf file:
Print the jacket out (ideally on cardstock).
Print "actual size" (100%).
To include the jacket inside (if any) print double-sided.
Use the crop marks and origami symbols to cut and fold the jacket.
Exact procedure depends on your tools and preferred methods.
Example procedure #1:
Use the origami mountain fold lines to score the fold lines (e.g. using a ruler and a penknife).
Use the crop marks to cut the edges off.
Make two mountain folds using the scored lines along the spine.
Example procedure #2:
Use the crop marks to cut away the left and right edge.
Make a valley fold by touching the origami dots symbols along the top edge together and then flatten the paper to make the fold and then unfold flat. Repeat this procedure with the origami dot symbols along the bottom edge.
Cut away the top and bottom edges (you may use the ends of the origami mountain fold lines as well as the edges of the jacket as guide to where to make these cuts).
Make two mountain folds by reversing the (valley) creases.
Insert the jacket into the storage box.
pdf_add_origami() to add origami symbols to pre-existing Boardgame Barrio's Small Board Game Jackets.
# Template `front`, `back`, and `spine` if (requireNamespace("piecepackr", quietly = TRUE)) { f1 <- pdf_create_4x6_jacket() unlink(f1) } # Fill `front`, `back`, and `spine` if (requireNamespace("piecepackr", quietly = TRUE)) { f2 <- pdf_create_4x6_jacket(front = "red", back = "blue", spine = "purple") unlink(f2) } # Grob `front`, `back`, and `spine` if (requireNamespace("piecepackr", quietly = TRUE) && require("gridpattern", quietly = TRUE)) { pal <- grDevices::palette() herringbone <- patternGrob("polygon_tiling", type = "herringbone", fill = pal[2], spacing = 0.1) rhombille <- patternGrob("polygon_tiling", type = "rhombille", fill = pal[3], spacing = 0.3) pythagorean <- patternGrob("polygon_tiling", type = "pythagorean", fill = pal[4], spacing = 0.1) f3 <- pdf_create_4x6_jacket(front = herringbone, back = pythagorean, spine = rhombille) unlink(f3) }# Template `front`, `back`, and `spine` if (requireNamespace("piecepackr", quietly = TRUE)) { f1 <- pdf_create_4x6_jacket() unlink(f1) } # Fill `front`, `back`, and `spine` if (requireNamespace("piecepackr", quietly = TRUE)) { f2 <- pdf_create_4x6_jacket(front = "red", back = "blue", spine = "purple") unlink(f2) } # Grob `front`, `back`, and `spine` if (requireNamespace("piecepackr", quietly = TRUE) && require("gridpattern", quietly = TRUE)) { pal <- grDevices::palette() herringbone <- patternGrob("polygon_tiling", type = "herringbone", fill = pal[2], spacing = 0.1) rhombille <- patternGrob("polygon_tiling", type = "rhombille", fill = pal[3], spacing = 0.3) pythagorean <- patternGrob("polygon_tiling", type = "pythagorean", fill = pal[4], spacing = 0.1) f3 <- pdf_create_4x6_jacket(front = herringbone, back = pythagorean, spine = rhombille) unlink(f3) }
pdf_create_wallet() creates print-and-play card origami wallets pdfs.
pdf_create_wallet( output = NULL, ..., front = NULL, back = NULL, spine = NULL, bleed = unit(0, "in"), paper = getOption("papersize", "letter") )pdf_create_wallet( output = NULL, ..., front = NULL, back = NULL, spine = NULL, bleed = unit(0, "in"), paper = getOption("papersize", "letter") )
output |
Output pdf filename. |
... |
Ignored. |
front |
Fill color/pattern/gradient or grob for front cover section of wallet.
Will be drawn in a rotated masked viewport with a
width of |
back |
Fill color/pattern/gradient or grob for back cover section of wallet.
Will be drawn in a rotated masked viewport with a
width of |
spine |
Fill color/pattern/gradient or grob for spine section of wallet.
Will be drawn in a masked viewport with a
width of |
bleed |
Bleed zone size to assume:
|
paper |
Paper size. Usually either "letter" or "a4" but in certain circumstances can be one of "letter", "a4", "poker", "bridge", "legal", "a5", "a3", "special". |
To make the wallets from the pdf files:
Print out two-sided flipping on the long edge
Using the crop marks on the first page (the page showing the "spine") trim the edges with a cutting tool (the four dots should now be at the corner of each page).
Make the four corner valley folds each labeled "Folds 1"
Make the two valley folds each labeled "Folds 2"
Flip over the paper and make the two valley folds each labeled "Folds 3"
Fold in half (valley fold)
output pdf file name invisibly.
As a side effect creates a print-and-play card wallet pdf file.
# Template `front`, `back`, and `spine` if (requireNamespace("piecepackr", quietly = TRUE) && getRversion() >= "4.1") { f1 <- pdf_create_wallet() unlink(f1) } # Fill `front`, `back`, and `spine` if (requireNamespace("piecepackr", quietly = TRUE) && getRversion() >= "4.1") { f2 <- pdf_create_wallet(front = "red", back = "blue", spine = "purple") unlink(f2) } # Grob `front`, `back`, and `spine` with bleed if (requireNamespace("piecepackr", quietly = TRUE) && getRversion() >= "4.1" && require("gridpattern", quietly = TRUE)) { pal <- grDevices::palette() herringbone <- patternGrob("polygon_tiling", type = "herringbone", fill = pal[2], spacing = 0.1) rhombille <- patternGrob("polygon_tiling", type = "rhombille", fill = pal[3], spacing = 0.2) pythagorean <- patternGrob("polygon_tiling", type = "pythagorean", fill = pal[4], spacing = 0.1) f3 <- pdf_create_wallet(front = herringbone, back = rhombille, spine = pythagorean, bleed = TRUE) unlink(f3) }# Template `front`, `back`, and `spine` if (requireNamespace("piecepackr", quietly = TRUE) && getRversion() >= "4.1") { f1 <- pdf_create_wallet() unlink(f1) } # Fill `front`, `back`, and `spine` if (requireNamespace("piecepackr", quietly = TRUE) && getRversion() >= "4.1") { f2 <- pdf_create_wallet(front = "red", back = "blue", spine = "purple") unlink(f2) } # Grob `front`, `back`, and `spine` with bleed if (requireNamespace("piecepackr", quietly = TRUE) && getRversion() >= "4.1" && require("gridpattern", quietly = TRUE)) { pal <- grDevices::palette() herringbone <- patternGrob("polygon_tiling", type = "herringbone", fill = pal[2], spacing = 0.1) rhombille <- patternGrob("polygon_tiling", type = "rhombille", fill = pal[3], spacing = 0.2) pythagorean <- patternGrob("polygon_tiling", type = "pythagorean", fill = pal[4], spacing = 0.1) f3 <- pdf_create_wallet(front = herringbone, back = rhombille, spine = pythagorean, bleed = TRUE) unlink(f3) }
ghostscript
pdf_gs() processes the pdf file with ghostscript.
This may prevent issues with other pdf processing functions like pdftools::pdf_pagesize().
pdf_gs(input, output = NULL, ..., args = character(0L))pdf_gs(input, output = NULL, ..., args = character(0L))
input |
Input pdf filename. |
output |
Output pdf filename. |
... |
Ignored. |
args |
Arguments to pass to ghostscript.
We automatically add |
tools::find_gs_cmd() and https://ghostscript.readthedocs.io/en/latest/
if (nzchar(tools::find_gs_cmd())) { f1 <- pdf_create_blank() f2 <- pdf_gs(f1) unlink(f1) unlink(f2) }if (nzchar(tools::find_gs_cmd())) { f1 <- pdf_create_blank() f2 <- pdf_gs(f1) unlink(f1) unlink(f2) }
pdf_orientation() tells whether a pdf is in portrait
or landscape mode.
pdf_orientation(input, ...)pdf_orientation(input, ...)
input |
Input pdf filename. |
... |
Ignored. |
A character vector with a length equal to the number of pages in input.
f1 <- pdf_create_blank(width = 8.5, height = 11) pdf_orientation(f1) f2 <- pdf_create_blank(width = 11, height = 8.5, length = 2L) pdf_orientation(f2) unlink(f1) unlink(f2)f1 <- pdf_create_blank(width = 8.5, height = 11) pdf_orientation(f1) f2 <- pdf_create_blank(width = 11, height = 8.5, length = 2L) pdf_orientation(f2) unlink(f1) unlink(f2)
pdf_pages() calculates an integer vector of subset of pdf pages.
pdf_pages( input, ..., pages = c("all", "even", "odd", "2-up saddle stitch", "interleave", "interleave_first", "interleave_last") )pdf_pages( input, ..., pages = c("all", "even", "odd", "2-up saddle stitch", "interleave", "interleave_first", "interleave_last") )
input |
Input pdf filename. |
... |
Ignored. |
pages |
A positive numeric vector of pages to include, a negative numeric vector of pages to exclude, or a string:
The functions
|
An integer vector.
f <- pdf_create_blank(length = 8L) pdf_pages(f, pages = 1:4) pdf_pages(f, pages = -(1:4)) pdf_pages(f, pages = "all") pdf_pages(f, pages = "even") pdf_pages(f, pages = "odd") pdf_pages(f, pages = "interleave") pdf_pages(f, pages = "interleave_first") pdf_pages(f, pages = "interleave_last") unlink(f) # Clean upf <- pdf_create_blank(length = 8L) pdf_pages(f, pages = 1:4) pdf_pages(f, pages = -(1:4)) pdf_pages(f, pages = "all") pdf_pages(f, pages = "even") pdf_pages(f, pages = "odd") pdf_pages(f, pages = "interleave") pdf_pages(f, pages = "interleave_first") pdf_pages(f, pages = "interleave_last") unlink(f) # Clean up
pdf_paper() infers the paper size of a PDF document
pdf_paper(input)pdf_paper(input)
input |
Input pdf filename. |
A character vector.
f <- pdf_create_blank(width = 8.5, height = 11) pdf_paper(f) unlink(f)f <- pdf_create_blank(width = 8.5, height = 11) pdf_paper(f) unlink(f)
pdfxup
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.
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") )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") )
input |
Input pdf filename. |
output |
Output pdf filename. |
... |
Ignored. |
ncol, nrow
|
Number of columns/rows per page. |
byrow |
If |
booklet |
If |
orientation |
Either |
paper |
Paper size (e.g. |
margins |
Margin of pages of the new document as a |
intspaces |
Space between pages as a |
innermargins |
Inner margin between frame and page as a |
framewidth |
Width of the frame around each page as a |
default.units |
Default units when a numeric value is passed for
|
clip |
If |
pages |
A positive numeric vector of pages to include, a negative numeric vector of pages to exclude, or a string:
The functions
|
bb_pages |
Pages to use when computing the bounding box (see |
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")
output pdf file name invisibly.
As a side effect creates an n-up pdf.
https://ctan.org/tex-archive/support/pdfxup for more information about pdfxup
f1 <- system.file("doc", "Sweave.pdf", package = "utils") if (nzchar(Sys.which("pdfxup")) && file.exists(f1)) { f2 <- pdf_pdfxup_booklet(f1) unlink(f2) }f1 <- system.file("doc", "Sweave.pdf", package = "utils") if (nzchar(Sys.which("pdfxup")) && file.exists(f1)) { f2 <- pdf_pdfxup_booklet(f1) unlink(f2) }
pdf_rasterize() re-renders a pdf by rasterizing each page.
pdf_rasterize(input, output = NULL, ..., dpi = getOption("pnpmisc.dpi", 300))pdf_rasterize(input, output = NULL, ..., dpi = getOption("pnpmisc.dpi", 300))
input |
Input pdf filename. |
output |
Output pdf filename. |
... |
Passed to |
dpi |
Dots per inch.
Passed to |
output pdf file name invisibly.
As a side effect creates a rasterized pdf.
pdf_apply() which this function wraps.
f1 <- pdf_create_blank(length = 2L, paper = "letter") f2 <- pdf_rasterize(f1, dpi = 75) unlink(f1) unlink(f2)f1 <- pdf_create_blank(length = 2L, paper = "letter") f2 <- pdf_rasterize(f1, dpi = 75) unlink(f1) unlink(f2)
pdf_render_bm_list() renders all pages of a pdf into bittermelon pixmap objects.
pdf_render_bm_list(input, ..., dpi = getOption("pnpmisc.dpi", 300))pdf_render_bm_list(input, ..., dpi = getOption("pnpmisc.dpi", 300))
input |
Input pdf filename. |
... |
Ignored. |
dpi |
Dots per inch.
Passed to |
A bittermelon::bm_list() of bittermelon::bm_pixmap() objects.
if (requireNamespace("bittermelon", quietly = TRUE)) { f <- pdf_create_wallet() bml <- pdf_render_bm_list(f, dpi = 75) grid::grid.raster(bml[[1L]]) unlink(f) }if (requireNamespace("bittermelon", quietly = TRUE)) { f <- pdf_create_wallet() bml <- pdf_render_bm_list(f, dpi = 75) grid::grid.raster(bml[[1L]]) unlink(f) }
pdf_render_bm_pixmap() renders a pdf page into a bittermelon pixmap object.
pdf_render_bm_pixmap( input, ..., page = 1L, dpi = getOption("pnpmisc.dpi", 300) )pdf_render_bm_pixmap( input, ..., page = 1L, dpi = getOption("pnpmisc.dpi", 300) )
input |
Input pdf filename. |
... |
Ignored. |
page |
Integer of page to render. |
dpi |
Dots per inch.
Passed to |
A bittermelon::bm_pixmap() object.
pdftools::pdf_render_page(), pdf_render_raster(), pdf_render_bm_list()
if (requireNamespace("bittermelon", quietly = TRUE)) { f <- pdf_create_wallet() bm <- pdf_render_bm_pixmap(f, page = 1L, dpi = 75) grid::grid.raster(bm) unlink(f) }if (requireNamespace("bittermelon", quietly = TRUE)) { f <- pdf_create_wallet() bm <- pdf_render_bm_pixmap(f, page = 1L, dpi = 75) grid::grid.raster(bm) unlink(f) }
pdf_render_raster() renders a pdf page into a raster object.
pdf_render_raster(input, ..., page = 1L, dpi = 300, native = FALSE)pdf_render_raster(input, ..., page = 1L, dpi = 300, native = FALSE)
input |
Input pdf filename. |
... |
Ignored. |
page |
Integer of page to render. |
dpi |
Dots per inch.
Passed to |
native |
If |
If native = TRUE returns a nativeRaster object else a raster object.
pdftools::pdf_render_page(), pdf_render_bm_pixmap()
if (requireNamespace("bittermelon", quietly = TRUE)) { f <- pdf_create_wallet() r <- pdf_render_raster(f, page = 1L, dpi = 75) grid::grid.raster(r) unlink(f) }if (requireNamespace("bittermelon", quietly = TRUE)) { f <- pdf_create_wallet() r <- pdf_render_raster(f, page = 1L, dpi = 75) grid::grid.raster(r) unlink(f) }
pdf_rep() repeats pages of a pdf similar to base::rep().
pdf_rep( input, output = NULL, ..., pages = "all", times = 1L, length.out = NA_integer_, each = 1L )pdf_rep( input, output = NULL, ..., pages = "all", times = 1L, length.out = NA_integer_, each = 1L )
input |
Input pdf filename. |
output |
Output pdf filename. |
... |
Ignored. |
pages |
A positive numeric vector of pages to include, a negative numeric vector of pages to exclude, or a string:
The functions
|
times, length.out, each
|
Passed to |
output pdf file name invisibly.
As a side effect creates a pdf with repeated pages.
f1 <- pdf_create_blank(length = 3L, paper = "letter") f2 <- pdf_rep(f1, times = 2L) f3 <- pdf_rep(f1, pages = 1:2, each = 2L) unlink(f1) unlink(f2) unlink(f3)f1 <- pdf_create_blank(length = 3L, paper = "letter") f2 <- pdf_rep(f1, times = 2L) f3 <- pdf_rep(f1, pages = 1:2, each = 2L) unlink(f1) unlink(f2) unlink(f3)
pdf_rm_crosshairs() removes unwanted crosshairs.
pdf_rm_crosshairs(input, output = NULL, ..., layout = "poker_3x2_bleed")pdf_rm_crosshairs(input, output = NULL, ..., layout = "poker_3x2_bleed")
input |
Input pdf filename. |
output |
Output pdf filename. |
... |
Passed to |
layout |
Either a layout preset name in |
In order to work the PnP layout needs a solid color bleed.
The default layout supports Galdor's Grip (PnP letter size v1).
output pdf file name invisibly.
As a side effect removes from crosshairs from a pdf.
if (requireNamespace("bittermelon", quietly = TRUE) && requireNamespace("piecepackr", quietly = TRUE) && utils::packageVersion("piecepackr") >= "1.14.0-5") { f1 <- pdf_create_blank(length = 2L, width = 11, height = 8.5) f2 <- pdf_add_crosshairs(f1, pages = "all", layout = "poker_3x2_bleed") f3 <- pdf_rm_crosshairs(f2, pages = "odd", layout = "poker_3x2_bleed", dpi = 75) unlink(f1) unlink(f2) unlink(f3) }if (requireNamespace("bittermelon", quietly = TRUE) && requireNamespace("piecepackr", quietly = TRUE) && utils::packageVersion("piecepackr") >= "1.14.0-5") { f1 <- pdf_create_blank(length = 2L, width = 11, height = 8.5) f2 <- pdf_add_crosshairs(f1, pages = "all", layout = "poker_3x2_bleed") f3 <- pdf_rm_crosshairs(f2, pages = "odd", layout = "poker_3x2_bleed", dpi = 75) unlink(f1) unlink(f2) unlink(f3) }
pdf_scale() scales the contents of a pdf centered within the page.
pdf_scale(input, output = NULL, ..., scale)pdf_scale(input, output = NULL, ..., scale)
input |
Input pdf filename. |
output |
Output pdf filename. |
... |
Passed to |
scale |
A numeric scalar to scale the content by.
Values less than 1 shrink the content within the page; values greater than 1 enlarge it.
By default the original content is not rescaled.
Note this also adjusts the size of the |
output pdf file name invisibly.
As a side effect creates a scaled pdf file.
input <- pdf_create_blank(paper = "letter", bg = "blue") output <- pdf_scale(input, scale = 0.9, dpi = 75) pdf_width(output) pdf_height(output) unlink(input) unlink(output)input <- pdf_create_blank(paper = "letter", bg = "blue") output <- pdf_scale(input, scale = 0.9, dpi = 75) pdf_width(output) pdf_height(output) unlink(input) unlink(output)
xmpdf functionsThese functions wrap around the utilities in the xmpdf package
but alters the arguments to match this package's conventions:
the first two arguments must be input and output,
by default output = tempfile(fileext = ".pdf"), and all other
arguments must be named.
pdf_set_bookmarks(input, output = NULL, ..., bookmarks) pdf_set_docinfo(input, output = NULL, ..., docinfo) pdf_set_xmp(input, output = NULL, ..., xmp)pdf_set_bookmarks(input, output = NULL, ..., bookmarks) pdf_set_docinfo(input, output = NULL, ..., docinfo) pdf_set_xmp(input, output = NULL, ..., xmp)
input |
Input pdf filename. |
output |
Output pdf filename. |
... |
Currently ignored. |
bookmarks |
|
docinfo |
See |
xmp |
See |
output filename of new pdf file invisibly.
xmpdf::set_bookmarks(), xmpdf::set_docinfo(), xmpdf::set_xmp()
f1 <- pdf_create_blank(length = 2L) if (requireNamespace("xmpdf", quietly = TRUE) && xmpdf::supports_set_bookmarks()) { bm <- data.frame(title = c("Page 1", "Page 2"), page = c(1, 2)) f2 <- pdf_set_bookmarks(f1, bookmarks = bm) unlink(f2) } if (requireNamespace("xmpdf", quietly = TRUE) && xmpdf::supports_set_docinfo()) { di <- xmpdf::docinfo(title = "A Title", author = "The Author") f3 <- pdf_set_docinfo(f1, docinfo = di) unlink(f3) } if (requireNamespace("xmpdf", quietly = TRUE) && xmpdf::supports_set_xmp()) { xmp <- xmpdf::xmp(title = "A Title", creator = "The Author") f4 <- pdf_set_xmp(f1, xmp = xmp) unlink(f4) } unlink(f1)f1 <- pdf_create_blank(length = 2L) if (requireNamespace("xmpdf", quietly = TRUE) && xmpdf::supports_set_bookmarks()) { bm <- data.frame(title = c("Page 1", "Page 2"), page = c(1, 2)) f2 <- pdf_set_bookmarks(f1, bookmarks = bm) unlink(f2) } if (requireNamespace("xmpdf", quietly = TRUE) && xmpdf::supports_set_docinfo()) { di <- xmpdf::docinfo(title = "A Title", author = "The Author") f3 <- pdf_set_docinfo(f1, docinfo = di) unlink(f3) } if (requireNamespace("xmpdf", quietly = TRUE) && xmpdf::supports_set_xmp()) { xmp <- xmpdf::xmp(title = "A Title", creator = "The Author") f4 <- pdf_set_xmp(f1, xmp = xmp) unlink(f4) } unlink(f1)
pdf_width() and pdf_height() get the dimensions of the pdf file pages.
pdf_width(input, ..., units = "inches", numeric = FALSE) pdf_height(input, ..., units = "inches", numeric = FALSE)pdf_width(input, ..., units = "inches", numeric = FALSE) pdf_height(input, ..., units = "inches", numeric = FALSE)
input |
Input pdf filename. |
... |
Ignored. |
units |
Units to use. See |
numeric |
If |
If numeric = TRUE a numeric vector else a grid::unit() object.
f <- pdf_create_blank(width = 8.5, height = 11) pdf_width(f) pdf_height(f, units = "cm") pdf_height(f, units = "mm", numeric = TRUE) unlink(f)f <- pdf_create_blank(width = 8.5, height = 11) pdf_width(f) pdf_height(f, units = "cm") pdf_height(f, units = "mm", numeric = TRUE) unlink(f)
zip_extract_bm_pixmap() extracts/renders an image from a zipfile into a bittermelon::bm_pixmap() object.
zip_extract_bm_pixmap(zipfile, filename, ...)zip_extract_bm_pixmap(zipfile, filename, ...)
zipfile |
Path to a zip file |
filename |
Filename within zip file |
... |
If |
A bittermelon::bm_pixmap() object.
## Not run: # "https://boardgamegeek.com/filepage/279177/packvelopes-storage-boxes" zipfile <- "Everdeck_Packvelopes.zip" bm <- zip_extract_bm_pixmap(zipfile, "Red and Black.pdf") # https://boardgamegeek.com/filepage/62704/cards-in-png-format zipfile <- "decktet_cards_PNG.zip" bm <- zip_extract_bm_pixmap(zipfile, "PNG/a_card_cover3.png") ## End(Not run)## Not run: # "https://boardgamegeek.com/filepage/279177/packvelopes-storage-boxes" zipfile <- "Everdeck_Packvelopes.zip" bm <- zip_extract_bm_pixmap(zipfile, "Red and Black.pdf") # https://boardgamegeek.com/filepage/62704/cards-in-png-format zipfile <- "decktet_cards_PNG.zip" bm <- zip_extract_bm_pixmap(zipfile, "PNG/a_card_cover3.png") ## End(Not run)