minipdf
is a package for creating simple, single-page PDF documents.
You can install the development version from GitHub with:
# install.packages("devtools")
devtools::install_github("coolbutuseless/minipdf")
Hello-world.pdf
doc <- PDFDocument$new(width = 200, height = 60, fontname = 'Helvetica-Bold')
doc$rect(0, 0, 200, 60, fill = '#123456', stroke = NULL)
doc$text("Hello World!", x = 10, y = 15, fontsize = 20, fill = 'white')
doc$line(0, 10, 200, 10, stroke = 'grey80')
doc$save("man/figures/helloworld.pdf")
By copying and modifying/transforming a basic shape (e.g. a diamond) complex patterns can be built.
xs <- c(0, 75, 150, 75, 0)
ys <- c(0, -50, 0, 50, 0)
diamond <- PDFPolygon$new(xs = xs, ys = ys, stroke = NULL)
d1a <- diamond$copy()$fill('darkred')$translate( 0, 50)
d1b <- diamond$copy()$fill('#123456')$translate(150, 50)
d1c <- diamond$copy()$fill('darkred')$translate(300, 50)
d2a <- diamond$copy()$fill('#123456')$translate( 0, 150)
d2b <- diamond$copy()$fill('darkred')$translate(150, 150)
d2c <- diamond$copy()$fill('#123456')$translate(300, 150)
d3 <- diamond$copy()$fill('#12345630')$
stroke('white')$
linewidth(2)$
translate(75, 100)$scale(2)
doc <- pdf_doc(width = 450, height = 200, d1a, d1b, d1c, d2a, d2b, d2c, d3)
doc$save("man/figures/diamonds.pdf")
Currently there is no support for annotations or any sort of text layout.
minipdf v0.2.1
and minidf v0.2.2
add_rect()
is now just rect()