pnpmisc

Table of Contents

Overview

{pnpmisc} is an R package to edit pdf files. 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.

The pdf editing functions in this package have the following conventions which allow them to be chained:

While some of the pdf editing functions are of general use the motivating goal of this package is to help me tweak existing print-and-play files to a format a little bit easier for me to physically manufacture using my preferred techniques and tools.

My personal print-and-play preferences:

Installation

You can install the development version using my R-universe universe:

install.packages('pnpmisc', repos = c('https://trevorld.r-universe.dev', 'https://cloud.r-project.org'))

or by using the {remotes} package:

remotes::install_github("trevorld/pnpmisc")

Examples

bm_split_layout() and grid_add_layout()

library("bittermelon")
library("pnpmisc")
# Download "A Nice Cuppa"
# <https://buttonshygames.itch.io/a-nice-cuppa>
input <- "A Nice Cuppa - PNP.pdf"
output <- "a_nice_cuppa_rules.pdf"
layout <- layout_preset("button_shy_rules")
bml <- input |> pdf_render_bm_pixmap() |>
    bm_split_layout(layout = layout)

layout <- transform(layout, angle = 0, name = paste0("page_", 1:8))
pdf(output, width = 11, height = 8.5)
grid_add_layout(bml, layout = layout)
grid_add_rects(layout = layout, gp = grid::gpar(lwd = 4))
dev.off()

pdf_add_crosshairs()

library("piecepackr")
library("pnpmisc")
# Download "A Nice Cuppa"
# <https://buttonshygames.itch.io/a-nice-cuppa>
input <- "A Nice Cuppa - PNP.pdf"
output <- "a_nice_cuppa_cards.pdf"
input |> pdf_subset(pages = -1L) |>
    pdf_add_crosshairs(output, layout = "button_shy_cards", pages = "even")
rm_temp_pdfs()

pdf_add_rects()

library("piecepackr")
library("pnpmisc")
# Download Mini Rogue (Original)
# <https://boardgamegeek.com/boardgame/199242/mini-rogue-a-roguelike-microgame/files>
input <- "Mini_Rogue_-_Cards_v1.2.1.pdf"
output <- "mini_rogue_cards.pdf"
input |> pdf_subset(pages = 1:2) |>
    pdf_add_rects(layout = "poker_3x3",
                  gp = grid::gpar(fill = NA, col = "white", lwd = 2)) |>
    pdf_add_crosshairs(output, pages = 2L, layout = "poker_3x3")
rm_temp_pdfs()

pdf_add_origami()

library("pnpmisc")
# Download Boardgame Barrio Small Box Game Jackets from
# <https://sites.google.com/view/boardgamebarrio/home>
input <- "SBG_Jacket_-_Animal_Upon_Animal.pdf"
output <- "animal_upon_animal_jacket.pdf"
input |> pdf_gs() |>
    pdf_subset(pages = 1L) |>
    pdf_add_origami(output)
rm_temp_pdfs()

pdf_create_wallet()

library("bittermelon")
library("grid")
library("gridpattern")
library("pnpmisc")
# Download "Numbsters"
# <https://buttonshygames.itch.io/numbsters>
input <- "Numbsters_PNP_letter_v1.2.pdf"
output <- "numbsters_wallet.pdf"
bm_cover <- pdf_render_bm_pixmap(input, page = 1L) |>
  bm_crop_layout(layout = "button_shy_rules", row = 1L, col = 4L)
bm_back <- pdf_render_bm_pixmap(input, page = 1L) |>
  bm_crop_layout(layout = "button_shy_rules", row = 1L, col = 3L)
bm_mouths <- pdf_render_bm_pixmap(input, page = 3L) |>
  bm_crop_layout(layout = "button_shy_cards", row = 1L, col = 2L, bleed = TRUE) |>
  bm_trim(bottom = 100, top = 100, left = 100, right = 100)

pat <- rasterGrob(bm_mouths, height = unit(8.25, "in"))
front <- gList(pat, rasterGrob(bm_cover, width = unit(1.8, "in")))
back <- gList(pat, rasterGrob(bm_back, width = unit(1.8, "in")))
spine <- rasterGrob(bm_rotate(bm_mouths, 90), width = unit(8.25, "in"))
pdf_create_wallet(output, front = front, back = back, spine = spine, bleed = 0.125)

pdf_pad_paper()

library("pnpmisc")
# Download Birdscaping from <https://boardgamegeek.com/boardgame/366484/birdscaping/files>
input <- list.files(pattern = "^Birdscaping_1.7")
output <- "birdscaping_cards.pdf"
pdf_combine(input) |>
	pdf_pad_paper(output)

pdf_rm_crosshairs()

library("pnpmisc")
# Download Galdor's Grip from <https://greggjewell.itch.io/galdors-grip>
input <- "GaldorsGrip_PnP_Cards_TGCBundle_EN_USL_v1.pdf"
output <- "galdors_grip_cards.pdf"
pdf_rm_crosshairs(input, output, pages = "odd", layout = "poker_3x2_bleed")

Related links

R packages

Some print-and-play links