| Title: | PDF Document Creator |
|---|---|
| Description: | PDF is a standard file format for laying out text and images in documents. At its core, these documents are sequences of objects defined in plain text. This package allows for the creation of PDF documents at a very low level without any library or graphics device dependencies. |
| Authors: | Mike Cheng [aut, cre, cph] |
| Maintainer: | Mike Cheng <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.7 |
| Built: | 2026-05-08 06:13:33 UTC |
| Source: | https://github.com/coolbutuseless/minipdf |
Convert clipping spec into PDF string
## S3 method for class 'clip_rect' as.character(x, ...) ## S3 method for class 'clip_polygon' as.character(x, ...) ## S3 method for class 'clip_list' as.character(x, ...)## S3 method for class 'clip_rect' as.character(x, ...) ## S3 method for class 'clip_polygon' as.character(x, ...) ## S3 method for class 'clip_list' as.character(x, ...)
x |
clip object created with |
... |
ignored |
string representing a clipping specification
pdf_dict as character stringRender pdf_dict as character string
## S3 method for class 'pdf_dict' as.character(x, depth = 0, ...)## S3 method for class 'pdf_dict' as.character(x, depth = 0, ...)
x |
|
depth |
print depth. Default: 0. Used to control indentation |
... |
ignored |
Character representation
pdf_stream to characterConvert pdf_stream to character
## S3 method for class 'pdf_stream' as.character(x, ...)## S3 method for class 'pdf_stream' as.character(x, ...)
x |
|
... |
ignored |
character string representation of a pdf stream object
Convert scale/rotate/translate specification to a PDF transformation string
## S3 method for class 'pdf_translate' as.character(x, ...) ## S3 method for class 'pdf_rotate' as.character(x, ...) ## S3 method for class 'pdf_scale' as.character(x, ...) ## S3 method for class 'pdf_transform_list' as.character(x, ...)## S3 method for class 'pdf_translate' as.character(x, ...) ## S3 method for class 'pdf_rotate' as.character(x, ...) ## S3 method for class 'pdf_scale' as.character(x, ...) ## S3 method for class 'pdf_transform_list' as.character(x, ...)
x |
transform specification |
... |
ignored |
String representing a PDF transformation matrix 'cm' operation
clip argumentDefine a clipping polygon for use as a clip argument
clip_polygon(xs, ys, id = NULL, rule = "winding")clip_polygon(xs, ys, id = NULL, rule = "winding")
xs, ys
|
vertex coordinates. Note: polygon will automatically be closed |
id |
A numeric vector used to separate vertices into multiple polygons. All vertices with the same id belong to the same polygon. Default: NULL means that all vertices belong to a single polygon. |
rule |
fill rule. 'winding' or 'evenodd'. Default: 'winding' |
clipping polygon specification
Other clipping functions:
clip_rect(),
pdf_clip_polygon(),
pdf_clip_rect()
doc <- create_pdf() |> pdf_rect(0, 0, 100, 100, clip = clip_polygon(xs = c(0, 100, 100), ys = c(0, 0, 100)))doc <- create_pdf() |> pdf_rect(0, 0, 100, 100, clip = clip_polygon(xs = c(0, 100, 100), ys = c(0, 0, 100)))
clip argumentDefine a clipping rectangle for use as a clip argument
clip_rect(x, y, width, height)clip_rect(x, y, width, height)
x, y
|
position |
width, height
|
size |
clipping rectangle specification
Other clipping functions:
clip_polygon(),
pdf_clip_polygon(),
pdf_clip_rect()
doc <- create_pdf() |> pdf_rect(0, 0, 100, 100, clip = clip_rect(50, 50, 200, 200))doc <- create_pdf() |> pdf_rect(0, 0, 100, 100, clip = clip_rect(50, 50, 200, 200))
Create an new PDF
create_pdf( width = 400, height = 400, title = NULL, author = NULL, creator = "minipdf/R", creation_date = strftime(Sys.time(), format = "D:%Y%m%d%H%M") )create_pdf( width = 400, height = 400, title = NULL, author = NULL, creator = "minipdf/R", creation_date = strftime(Sys.time(), format = "D:%Y%m%d%H%M") )
width, height
|
page size in pixels |
title, author, creator, creation_date
|
Document-level metainformation about this file. Set value to NULL to exclude from PDF. |
pdf_doc object (i.e. a named list)
create_pdf()create_pdf()
Add a cubic bezier to a PDF doc
pdf_bezier( doc, x0, y0, x1, y1, x2, y2, x3, y3, ..., gp = pgpar(), tf = NULL, clip = NULL )pdf_bezier( doc, x0, y0, x1, y1, x2, y2, x3, y3, ..., gp = pgpar(), tf = NULL, clip = NULL )
doc |
A |
x0, y0, x1, y1, x2, y2, x3, y3
|
start point, two control points and end point of bezier curve |
... |
further arguments to be added to |
gp |
A named list |
tf |
either a single transform ( |
clip |
either a single clip ( |
pdf_doc
Other object creation functions:
pdf_circle(),
pdf_image(),
pdf_line(),
pdf_polygon(),
pdf_polyline(),
pdf_rect(),
pdf_text()
doc <- create_pdf() |> pdf_bezier(seq(0, 400, 6), 0, 250, 25, 25, 250, 400, 400, lwd = 1, alpha = 0.2)doc <- create_pdf() |> pdf_bezier(seq(0, 400, 6), 0, 250, 25, 25, 250, 400, 400, lwd = 1, alpha = 0.2)
Add a circle to a PDF doc
pdf_circle(doc, x, y, r, ..., gp = pgpar(), tf = NULL, clip = NULL)pdf_circle(doc, x, y, r, ..., gp = pgpar(), tf = NULL, clip = NULL)
doc |
A |
x, y, r
|
position of centre and radius of circle (Length = 1 or n) |
... |
further arguments to be added to |
gp |
A named list |
tf |
either a single transform ( |
clip |
either a single clip ( |
pdf_doc
Other object creation functions:
pdf_bezier(),
pdf_image(),
pdf_line(),
pdf_polygon(),
pdf_polyline(),
pdf_rect(),
pdf_text()
doc <- create_pdf() |> pdf_circle(x = 200, y = 200, r = 50)doc <- create_pdf() |> pdf_circle(x = 200, y = 200, r = 50)
Clipping regions are cumulative, and these is no operation to expand the
global clipping region.
use local clipping with the clip argument to individual objects.
pdf_clip_polygon(doc, xs, ys, id = NULL, rule = "winding", tf = NULL)pdf_clip_polygon(doc, xs, ys, id = NULL, rule = "winding", tf = NULL)
doc |
A |
xs, ys
|
vertex coordinates. Note: polygon will automatically be closed |
id |
A numeric vector used to separate vertices into multiple polygons. All vertices with the same id belong to the same polygon. Default: NULL means that all vertices belong to a single polygon. |
rule |
fill rule. 'winding' or 'evenodd'. Default: 'winding' |
tf |
either a single transform ( |
pdf_doc
Other clipping functions:
clip_polygon(),
clip_rect(),
pdf_clip_rect()
Other global clipping functions:
pdf_clip_rect()
doc <- create_pdf() |> pdf_clip_polygon(xs = c(0, 100, 100), ys = c(0, 0, 100))doc <- create_pdf() |> pdf_clip_polygon(xs = c(0, 100, 100), ys = c(0, 0, 100))
Clipping regions are cumulative, and these is no operation to expand the
global clipping region.
use local clipping with the clip argument to individual objects.
pdf_clip_rect(doc, x, y, width, height, tf = NULL)pdf_clip_rect(doc, x, y, width, height, tf = NULL)
doc |
A |
x, y
|
position |
width, height
|
size |
tf |
either a single transform ( |
pdf_doc
Other clipping functions:
clip_polygon(),
clip_rect(),
pdf_clip_polygon()
Other global clipping functions:
pdf_clip_polygon()
doc <- create_pdf() |> pdf_clip_rect(0, 0, 200, 200)doc <- create_pdf() |> pdf_clip_rect(0, 0, 200, 200)
Add image to a PDF doc
pdf_image( doc, im, x, y, scale = 1, interpolate = FALSE, ..., gp = pgpar(), tf = NULL, clip = NULL )pdf_image( doc, im, x, y, scale = 1, interpolate = FALSE, ..., gp = pgpar(), tf = NULL, clip = NULL )
doc |
A |
im |
Image represented as a numeric matrix or array with all values in range [0, 255].
|
x, y
|
position of bottom-left corner of image. (Length = 1) |
scale |
scale factor when rendering image Default: 1. (Length = 1) |
interpolate |
Should pixel values be interpolated? Default: FALSE. (Length = 1) |
... |
further arguments to be added to |
gp |
A named list |
tf |
either a single transform ( |
clip |
either a single clip ( |
pdf_doc
Other object creation functions:
pdf_bezier(),
pdf_circle(),
pdf_line(),
pdf_polygon(),
pdf_polyline(),
pdf_rect(),
pdf_text()
im <- matrix(1:100, 10, 10) doc <- create_pdf() |> pdf_image(im, 20, 20, scale = 2)im <- matrix(1:100, 10, 10) doc <- create_pdf() |> pdf_image(im, 20, 20, scale = 2)
Add a line to a PDF doc
pdf_line(doc, x1, y1, x2, y2, ..., gp = pgpar(), tf = NULL, clip = NULL)pdf_line(doc, x1, y1, x2, y2, ..., gp = pgpar(), tf = NULL, clip = NULL)
doc |
A |
x1, y1, x2, y2
|
endpoints (Length = 1 or n) |
... |
further arguments to be added to |
gp |
A named list |
tf |
either a single transform ( |
clip |
either a single clip ( |
pdf_doc
Other object creation functions:
pdf_bezier(),
pdf_circle(),
pdf_image(),
pdf_polygon(),
pdf_polyline(),
pdf_rect(),
pdf_text()
doc <- create_pdf() |> pdf_line(10, 10, 100, 100, col = 'red')doc <- create_pdf() |> pdf_line(10, 10, 100, 100, col = 'red')
Start a new page in a PDF odc
pdf_newpage(doc)pdf_newpage(doc)
doc |
A |
doc with new page added (and made the current page)
create_pdf() |> pdf_newpage()create_pdf() |> pdf_newpage()
Add a polygon to a PDF doc
pdf_polygon(doc, xs, ys, id = NULL, ..., gp = pgpar(), tf = NULL, clip = NULL)pdf_polygon(doc, xs, ys, id = NULL, ..., gp = pgpar(), tf = NULL, clip = NULL)
doc |
A |
xs, ys
|
vertex coordinates. Note: polygon will automatically be closed |
id |
A numeric vector used to separate vertices into multiple polygons. All vertices with the same id belong to the same polygon. Default: NULL means that all vertices belong to a single polygon. |
... |
further arguments to be added to |
gp |
A named list |
tf |
either a single transform ( |
clip |
either a single clip ( |
pdf_doc
Other object creation functions:
pdf_bezier(),
pdf_circle(),
pdf_image(),
pdf_line(),
pdf_polyline(),
pdf_rect(),
pdf_text()
doc <- create_pdf() |> pdf_polygon(xs = c(100, 200, 200), ys = c(100, 100, 200))doc <- create_pdf() |> pdf_polygon(xs = c(100, 200, 200), ys = c(100, 100, 200))
Add a polyline to a PDF doc
pdf_polyline(doc, xs, ys, ..., gp = pgpar(), tf = NULL, clip = NULL)pdf_polyline(doc, xs, ys, ..., gp = pgpar(), tf = NULL, clip = NULL)
doc |
A |
xs, ys
|
vertex coordinates |
... |
further arguments to be added to |
gp |
A named list |
tf |
either a single transform ( |
clip |
either a single clip ( |
pdf_doc
Other object creation functions:
pdf_bezier(),
pdf_circle(),
pdf_image(),
pdf_line(),
pdf_polygon(),
pdf_rect(),
pdf_text()
doc <- create_pdf() |> pdf_polyline(xs = c(100, 200, 200), ys = c(100, 100, 200))doc <- create_pdf() |> pdf_polyline(xs = c(100, 200, 200), ys = c(100, 100, 200))
Add a rectangle to a PDF doc
pdf_rect(doc, x, y, width, height, ..., gp = pgpar(), tf = NULL, clip = NULL)pdf_rect(doc, x, y, width, height, ..., gp = pgpar(), tf = NULL, clip = NULL)
doc |
A |
x, y
|
position of lower left of rectangle (Length = 1 or n) |
width, height
|
width of height of rectangle (Length = 1 or n) |
... |
further arguments to be added to |
gp |
A named list |
tf |
either a single transform ( |
clip |
either a single clip ( |
pdf_doc
Other object creation functions:
pdf_bezier(),
pdf_circle(),
pdf_image(),
pdf_line(),
pdf_polygon(),
pdf_polyline(),
pdf_text()
doc <- create_pdf() |> pdf_rect(10, 10, 100, 100, gp = pgpar(fill = 'red'))doc <- create_pdf() |> pdf_rect(10, 10, 100, 100, gp = pgpar(fill = 'red'))
Global transformations are cumulative, and these is no operation to reset
the global transformation.
For local transformations use the tf argument for individual objects.
pdf_rotate(doc, rads, x = 0, y = 0)pdf_rotate(doc, rads, x = 0, y = 0)
doc |
A |
rads |
rotation angle in radians |
x, y
|
location to rotate around |
pdf_doc
Other transform functions:
pdf_scale(),
pdf_translate(),
tf_rotate(),
tf_scale(),
tf_translate()
Other global transform functions:
pdf_scale(),
pdf_translate()
doc <- create_pdf() |> pdf_rotate(rads = pi)doc <- create_pdf() |> pdf_rotate(rads = pi)
Global transformations are cumulative, and these is no operation to reset
the global transformation.
For local transformations use the tf argument for individual objects.
pdf_scale(doc, x, y = x)pdf_scale(doc, x, y = x)
doc |
A |
x, y
|
scale amount in each direction. If 'y' value is not specified it is made the same as the 'x' value |
pdf_doc
Other transform functions:
pdf_rotate(),
pdf_translate(),
tf_rotate(),
tf_scale(),
tf_translate()
Other global transform functions:
pdf_rotate(),
pdf_translate()
doc <- create_pdf() |> pdf_scale(x = 10)doc <- create_pdf() |> pdf_scale(x = 10)
Add text to a PDF doc
pdf_text( doc, text, x, y, fontfamily = "Helvetica", fontface = "plain", fontsize = 12, mode = 0, ..., gp = pgpar(), tf = NULL, clip = NULL )pdf_text( doc, text, x, y, fontfamily = "Helvetica", fontface = "plain", fontsize = 12, mode = 0, ..., gp = pgpar(), tf = NULL, clip = NULL )
doc |
A |
text |
string |
x, y
|
position (Length = 1 or N) |
fontfamily |
Font name. Default: 'Helvetica'. One of: "Helvetica", "Courier", "Times", "Symbol", "ZapfDingbats". 'sans', 'mono' and 'serif' also accepted for 'Helvetica', 'Courier' and 'Times', respectively. (Length = 1) |
fontface |
Font styling. Default: 'plain'. One of: 'plain', 'bold', 'italic', 'bold.italic' (Length = 1) |
fontsize |
Default: 12 (Length = 1) |
mode |
Default: 0 (Length = 1)
|
... |
further arguments to be added to |
gp |
A named list |
tf |
either a single transform ( |
clip |
either a single clip ( |
pdf_doc
Other object creation functions:
pdf_bezier(),
pdf_circle(),
pdf_image(),
pdf_line(),
pdf_polygon(),
pdf_polyline(),
pdf_rect()
doc <- create_pdf() |> pdf_text("Hello", x = 20, y = 20, fontsize = 50)doc <- create_pdf() |> pdf_text("Hello", x = 20, y = 20, fontsize = 50)
Global transformations are cumulative, and these is no operation to reset
the global transformation.
For local transformations use the tf argument for individual objects.
pdf_translate(doc, x, y)pdf_translate(doc, x, y)
doc |
A |
x, y
|
translation |
pdf_doc
Other transform functions:
pdf_rotate(),
pdf_scale(),
tf_rotate(),
tf_scale(),
tf_translate()
Other global transform functions:
pdf_rotate(),
pdf_scale()
doc <- create_pdf() |> pdf_translate(x = 10, y = 10)doc <- create_pdf() |> pdf_translate(x = 10, y = 10)
This is similar to grid::gpar() except that values can only
be scalars (i.e. length = 1)
pgpar( col = "black", fill = "black", alpha = 1, lty, lwd, lineend, linejoin, linemitre, rule )pgpar( col = "black", fill = "black", alpha = 1, lty, lwd, lineend, linejoin, linemitre, rule )
col, fill
|
set graphics parameters for this object |
alpha |
additional alpha applied to col, fill |
lty, lwd, lineend, linejoin, linemitre
|
line optins |
rule |
fill rule. 'winding' (default) or 'evenodd' |
a graphics parameter object
pgpar()pgpar()
Print a 'pdf' object to the console
## S3 method for class 'pdf_doc' print(x, ...)## S3 method for class 'pdf_doc' print(x, ...)
x |
pdf object |
... |
ignored |
None
tf argument)Create a rotation specification (for use as tf argument)
tf_rotate(rads, x = 0, y = 0)tf_rotate(rads, x = 0, y = 0)
rads |
rotation angle in radians |
x, y
|
location to rotate around |
rotation specification
Other transform functions:
pdf_rotate(),
pdf_scale(),
pdf_translate(),
tf_scale(),
tf_translate()
doc <- create_pdf() |> pdf_text(text = "hello", x = 0, y = 0, tf = tf_rotate(rads = pi))doc <- create_pdf() |> pdf_text(text = "hello", x = 0, y = 0, tf = tf_rotate(rads = pi))
tf argument)Create a scaling specification (for use as tf argument)
tf_scale(x, y = x)tf_scale(x, y = x)
x, y
|
scale amount in each direction. If 'y' value is not specified it is made the same as the 'x' value |
scale transform specification
Other transform functions:
pdf_rotate(),
pdf_scale(),
pdf_translate(),
tf_rotate(),
tf_translate()
doc <- create_pdf() |> pdf_text(text = "hello", x = 0, y = 0, tf = tf_scale(x = 10))doc <- create_pdf() |> pdf_text(text = "hello", x = 0, y = 0, tf = tf_scale(x = 10))
tf argument)Create a translation specification (for use as tf argument)
tf_translate(x, y)tf_translate(x, y)
x, y
|
translation |
translation specification
Other transform functions:
pdf_rotate(),
pdf_scale(),
pdf_translate(),
tf_rotate(),
tf_scale()
doc <- create_pdf() |> pdf_text(text = "hello", x = 0, y = 0, tf = tf_translate(x = 10, y = 10))doc <- create_pdf() |> pdf_text(text = "hello", x = 0, y = 0, tf = tf_translate(x = 10, y = 10))
Write pdf to file or string
write_pdf(doc, filename = NULL)write_pdf(doc, filename = NULL)
doc |
A |
filename |
Output filename. Default: NULL means no output to file but return a string representation of the PDF |
string or None
create_pdf() |> pdf_circle(200, 200, 50, lwd = 5, fill = 'hotpink') |> write_pdf() |> cat()create_pdf() |> pdf_circle(200, 200, 50, lwd = 5, fill = 'hotpink') |> write_pdf() |> cat()