Title: | Utilities for Print-and-Play Board Games |
---|---|
Description: | Utilities for print-and-play board games. |
Authors: | Trevor L. Davis [aut, cre] |
Maintainer: | Trevor L. Davis <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0-14 |
Built: | 2024-12-18 01:21:52 UTC |
Source: | https://github.com/trevorld/pnpmisc |
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 )
bm_crop_layout( page, ..., layout = "button_shy_cards", row = 1L, col = 1L, bleed = FALSE )
page |
A |
... |
Ignored for now. |
layout |
Either a layout preset name in |
row , col
|
The |
bleed |
Include the bleed (if available). |
A bittermelon::bm_pixmap()
object.
## 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)
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)
grid_add_cropmarks(..., layout = "poker_3x3", bleed = NULL)
... |
Passed to |
layout |
Either a layout preset name in |
bleed |
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_rects()
draws (rounded) rectangles around components of a print-and-play layout.
grid_add_crosshairs(..., layout = "poker_3x3")
grid_add_crosshairs(..., layout = "poker_3x3")
... |
Passed to |
layout |
Either a layout preset name in |
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_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 rectangles 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_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 = c("letter", "a4"), orientation = c("landscape", "portrait") )
layout_grid( nrow = 2L, ncol = 1L, width = 2.5, height = 3.5, bleed = 0, paper = c("letter", "a4"), orientation = c("landscape", "portrait") )
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 |
A data frame with columns "row", "col", "x", "y", "width", "height", "bleed", "paper", and "orientation".
# 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_preset()
calculates a layout data frame
for a named preset.
layout_names()
returns the supported layout presets.
layout_preset(name = "button_shy_cards") layout_names()
layout_preset(name = "button_shy_cards") layout_names()
name |
Preset name. Must be in |
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.
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 data frame with columns "row", "col", "x", "y", "width", "height", "bleed", "paper", and "orientation".
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", pages = "even", dpi = 300, bleed = NULL )
pdf_add_cropmarks( input, output = NULL, ..., layout = "poker_3x3", pages = "even", dpi = 300, bleed = NULL )
input |
Input pdf filename. |
output |
Output pdf filename. |
... |
Passed to |
layout |
Either a layout preset name in |
pages |
A positive numeric vector of pages to include, a negative numeric vector of pages to exclude, or a string:
|
dpi |
Dots per inch. Passed to |
bleed |
Passed to |
The original pdf document will be rasterized.
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", dpi = 75) 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", dpi = 75) 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", pages = "even", dpi = 300 )
pdf_add_crosshairs( input, output = NULL, ..., layout = "button_shy_cards", pages = "even", dpi = 300 )
input |
Input pdf filename. |
output |
Output pdf filename. |
... |
Passed to |
layout |
Either a layout preset name in |
pages |
A positive numeric vector of pages to include, a negative numeric vector of pages to exclude, or a string:
|
dpi |
Dots per inch. Passed to |
The default layout supports Button Shy games.
The original pdf document will be rasterized.
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", dpi = 75) 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", dpi = 75) unlink(input) unlink(output) }
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, ..., dpi = 300)
pdf_add_origami(input, output = NULL, ..., dpi = 300)
input |
Input pdf filename. |
output |
Output pdf filename. |
... |
Ignored. |
dpi |
Dots per inch. 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_rects()
adds (rounded) rectangles around components of a print-and-play layout.
pdf_add_rects( input, output = NULL, ..., layout = "poker_3x3", pages = "all", dpi = 300, r = unit(0, "in"), gp = gpar(col = "black", fill = NA, lwd = 1) )
pdf_add_rects( input, output = NULL, ..., layout = "poker_3x3", pages = "all", dpi = 300, r = unit(0, "in"), gp = gpar(col = "black", fill = NA, lwd = 1) )
input |
Input pdf filename. |
output |
Output pdf filename. |
... |
Ignored for now. |
layout |
Either a layout preset name in |
pages |
A positive numeric vector of pages to include, a negative numeric vector of pages to exclude, or a string:
|
dpi |
Dots per inch. Passed to |
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 origami symbols.
grid_add_rects()
, grid::grid.roundrect()
f1 <- pdf_create_blank(length = 2L, paper = "letter") f2 <- pdf_add_rects(f1, layout = "poker_3x3", dpi = 75) # "Remove" unwanted card border lines by covering up with white f3 <- pdf_add_rects(f2, layout = "poker_3x3", dpi = 75, 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", dpi = 75) # "Remove" unwanted card border lines by covering up with white f3 <- pdf_add_rects(f2, layout = "poker_3x3", dpi = 75, 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_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)
These 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
,
by default output = tempfile(fileext = ".pdf")
, and all other
arguments must be named.
pdf_compress(input, output = NULL, ...) pdf_rotate_pages(input, output = NULL, ..., pages = "all") pdf_subset(input, output = NULL, ..., pages = 1L)
pdf_compress(input, output = NULL, ...) pdf_rotate_pages(input, output = NULL, ..., pages = "all") pdf_subset(input, output = NULL, ..., pages = 1L)
input |
Input pdf filename. |
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:
|
output
filename of new pdf file invisibly.
qpdf::pdf_compress()
, qpdf::pdf_rotate_pages()
, qpdf::pdf_subset()
f1 <- pdf_create_blank(width = 6, height = 4) f2 <- pdf_compress(f1) f3 <- pdf_subset(f2, pages = 1L) f4 <- pdf_rotate_pages(f3, angle = 90) unlink(f1) unlink(f2) unlink(f3) unlink(f4)
f1 <- pdf_create_blank(width = 6, height = 4) f2 <- pdf_compress(f1) f3 <- pdf_subset(f2, pages = 1L) f4 <- pdf_rotate_pages(f3, angle = 90) unlink(f1) unlink(f2) unlink(f3) unlink(f4)
pdf_create_blank()
creates blank pdf pages.
pdf_create_blank( output = NULL, ..., length = 1L, paper = c("special", "letter", "a4"), orientation = c("portrait", "landscape"), width = 8.5, height = 11, bg = "white" )
pdf_create_blank( output = NULL, ..., length = 1L, paper = c("special", "letter", "a4"), orientation = c("portrait", "landscape"), width = 8.5, height = 11, bg = "white" )
output |
Output pdf filename. |
... |
Ignored. |
length |
Number of pages to create. |
paper |
Paper size. Either "letter", "a4", or "special". |
orientation |
Either "portrait" or "landscape". Ignored if |
width , height
|
Paper size in inches if |
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)
pdf_create_jacket()
creates a printable 4x6 photo box jacket.
pdf_create_jacket( output = NULL, ..., front = NULL, back = NULL, spine = NULL, paper = c("letter", "a4") )
pdf_create_jacket( output = NULL, ..., front = NULL, back = NULL, spine = NULL, paper = c("letter", "a4") )
output |
Output pdf filename. |
... |
Ignored. |
front |
Fill color/pattern/gradient or grob for front cover section of wallet.
Will be drawn in a viewport with a
width of 4.139 inches
and a height of 6.141 inches.
If |
back |
Fill color/pattern/gradient or grob for back cover section of wallet.
Will be drawn in a viewport with a
width of 4.139 inches
and a height of 6.141 inches.
If |
spine |
Fill color/pattern/gradient or grob for spine section of wallet.
Will be drawn in a rotated viewport with a
width of 6.141 inches
and a height of 1.052 inches.
If |
paper |
Paper size. Either "letter", "a4", or "special". |
To make the 4x6 photo jacket from the pdf file:
Print it out
Use the crop marks to trim off the left and right edge
Make the two indicated mountain folds on both sides of the spine
Trim off the top and bottom edge
Insert into the 4x6 photo box
pdf_add_origami()
to add origami symbols to pre-existing Boardgame Barrio's Small Board Game Jackets.
# Template `front`, `back`, and `spine` f1 <- pdf_create_jacket() unlink(f1) # Fill `front`, `back`, and `spine` f2 <- pdf_create_jacket(front = "red", back = "blue", spine = "purple") unlink(f2) # Grob `front`, `back`, and `spine` if (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_jacket(front = herringbone, back = pythagorean, spine = rhombille, bleed = TRUE) unlink(f3) }
# Template `front`, `back`, and `spine` f1 <- pdf_create_jacket() unlink(f1) # Fill `front`, `back`, and `spine` f2 <- pdf_create_jacket(front = "red", back = "blue", spine = "purple") unlink(f2) # Grob `front`, `back`, and `spine` if (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_jacket(front = herringbone, back = pythagorean, spine = rhombille, bleed = TRUE) 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 = c("letter", "a4") )
pdf_create_wallet( output = NULL, ..., front = NULL, back = NULL, spine = NULL, bleed = unit(0, "in"), paper = c("letter", "a4") )
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. Either "letter", "a4", or "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` f1 <- pdf_create_wallet() unlink(f1) # Fill `front`, `back`, and `spine` f2 <- pdf_create_wallet(front = "red", back = "blue", spine = "purple") unlink(f2) # Grob `front`, `back`, and `spine` with bleed if (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` f1 <- pdf_create_wallet() unlink(f1) # Fill `front`, `back`, and `spine` f2 <- pdf_create_wallet(front = "red", back = "blue", spine = "purple") unlink(f2) # Grob `front`, `back`, and `spine` with bleed if (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) }
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.
Automatically adds |
if (tools::find_gs_cmd()[[1L]] != "") { f1 <- pdf_create_blank() f2 <- pdf_gs(f1) unlink(f1) unlink(f2) }
if (tools::find_gs_cmd()[[1L]] != "") { 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_pad_paper()
makes a pdf file larger by padding it (i.e. adding space to the outside margins).
The original images are not rescaled.
pdf_pad_paper( input, output = NULL, ..., bg = "white", dpi = 300, paper = c("letter", "a4") )
pdf_pad_paper( input, output = NULL, ..., bg = "white", dpi = 300, paper = c("letter", "a4") )
input |
Input pdf filename. |
output |
Output pdf filename. |
... |
Ignored. |
bg |
|
dpi |
Dots per inch. Passed to |
paper |
Paper size. Either "letter", "a4", or "special". |
output
pdf file name invisibly.
As a side effect creates padded pdf file.
# 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_pad_paper(input, dpi = 75) pdf_width(output) pdf_height(output) unlink(output) output_a4 <- pdf_pad_paper(input, dpi = 75, 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_pad_paper(input, dpi = 75) pdf_width(output) pdf_height(output) unlink(output) output_a4 <- pdf_pad_paper(input, dpi = 75, paper = "a4") pdf_width(output_a4) pdf_height(output_a4) unlink(output_a4) unlink(input)
pdf_pages()
calculates an integer vector of subset of pdf pages.
pdf_pages(input, ..., pages = c("all", "even", "odd", "2-up saddle stitch"))
pdf_pages(input, ..., pages = c("all", "even", "odd", "2-up saddle stitch"))
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:
|
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") unlink(f) # Clean up
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") unlink(f) # Clean up
pdf_render_bm_pixmap()
renders a pdf page into a bittermelon pixmap object.
pdf_render_bm_pixmap(input, ..., page = 1L, dpi = 300)
pdf_render_bm_pixmap(input, ..., page = 1L, 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()
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_rm_crosshairs()
removes unwanted crosshairs.
pdf_rm_crosshairs( input, output = NULL, ..., layout = "poker_3x2_bleed", pages = "odd", dpi = 300 )
pdf_rm_crosshairs( input, output = NULL, ..., layout = "poker_3x2_bleed", pages = "odd", dpi = 300 )
input |
Input pdf filename. |
output |
Output pdf filename. |
... |
Ignored. |
layout |
Either a layout preset name in |
pages |
A positive numeric vector of pages to include, a negative numeric vector of pages to exclude, or a string:
|
dpi |
Dots per inch. Passed to |
In order to work the PnP layout needs a solid color bleed.
The default layout supports Galdor's Grip (PnP letter size v1).
The original pdf document will be rasterized.
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", dpi = 75) 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", dpi = 75) f3 <- pdf_rm_crosshairs(f2, pages = "odd", layout = "poker_3x2_bleed", dpi = 75) unlink(f1) unlink(f2) unlink(f3) }
These 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)