PDF Document creator

PDF Document creator

Details

  • fontname - default: Helvetica. Choose one of the standard PDF fonts: Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic, Helvetica, Helvetica-Bold, Helvetica-Oblique, Helvetica-BoldOblique, Courier, Courier-Bold, Courier-Oblique, Courier-BoldOblique, Symbol, ZapfDingbats

  • width.height document dimensions. Default 400x400

  • version Default: 1.2. Doesn't do anything other than set the string at the beginning of the PDF document.

  • ... PDF objects

Public fields

version

PDF spec version

width, height

document width and height

user_objects

User elements added to the document

setup_objects

standard PDF header objects not directly defined by the user Initialize a new PDF documentConfigure the setup objects and initialise the user_objects The setup objects are those PDF objects needed to initialise the page at the most basic level i.e.

  • set up a catalog

  • set up a list of pages

  • set up font information.

  • set up the list of page contents (which will get updated with each new object)

  • keep track of GraphicStates used by various objects

Active bindings

width, height

document width and height

all_objects

List containing all objects

objs

All strings for all objects

header

The header for this document

body

The body is just the collection of all objects

xref

Update a xref table based upon the current objectsand the offsets to the start of each object Each xref entry must be exactly 20bytes (include CRLF). Since I'm only using CR, I need to add an extra space at the end of each xref entry

offsets

For the XREF table, need to know the offset to each object from start of document

trailer

The trailer indicates the start of the XREF table and total length of all objects it represents (including the dummy/root object)

Methods

Public methods


Method new()

Usage

PDFDocument$new(
  ...,
  width = 400,
  height = 400,
  fontname = "Helvetica",
  version = 1.2
)

Arguments

...

user objects to add during initialisation

width, height

dimensions of PDF document

fontname

default font for document (Default: 'Helvetica')

version

PDF specifcation version. Default: 1.2 Append user-defined objects to document


Method append()

Usage

PDFDocument$append(..., position = NULL)

Arguments

...

objects

position

where should the objects be inserted in the user object list? Default: NULL means to append at end of object list. A value of "1" means to insert at start of object list. Replace an object at the given position


Method replace()

Usage

PDFDocument$replace(pdf_object, position)

Arguments

pdf_object

User defined PDF object e.g. TODO

position

numeric index in object list Delete the object at the given position


Method delete()

Usage

PDFDocument$delete(position)

Arguments

position

numeric index in object list Character reprsetntatino of PDF document as a single string


Method as_character()

Usage

PDFDocument$as_character(...)

Arguments

...

ignored Print


Method print()

Usage

PDFDocument$print(...)

Arguments

...

ignored Save to PDF file


Method save()

Usage

PDFDocument$save(filename, ...)

Arguments

filename

output filename

...

ignored


Method copy()

Deep copy of this document Show the PDF in the defined R viewer

Usage

PDFDocument$copy()


Method show()

Usage

PDFDocument$show(viewer = getOption("viewer", utils::browseURL))

Arguments

viewer

which viewer to use


Method text()

Initialize a stream object representing a text

Usage

PDFDocument$text(text, x, y, fontsize, text_mode, ...)

Arguments

text

text

x, y

location

fontsize, text_mode

text settings [optional]

...

initial named attributes of this object


Method rect()

Initialize a stream object representing a rectangle

Usage

PDFDocument$rect(x, y, width, height, ...)

Arguments

x, y, width, height

specificaiton of rectangle extents

...

initial named attributes of this object


Method line()

Initialize a stream object representing a line

Usage

PDFDocument$line(x1, y1, x2, y2, ...)

Arguments

x1, y1, x2, y2

line start/end coordinates

...

initial named attributes of this object


Method circle()

Initialize a stream object representing a circle

Usage

PDFDocument$circle(x, y, r, ...)

Arguments

x, y

centre of circle

r

radius

...

initial named attributes of this object


Method polygon()

Initialize a stream object representing a polygon

Usage

PDFDocument$polygon(xs, ys, ...)

Arguments

xs, ys

coordinates of polygon vertices

...

initial named attributes of this object


Method polyline()

Initialize a stream object representing a polyline

Usage

PDFDocument$polyline(xs, ys, ...)

Arguments

xs, ys

numeric vectors of x, ycoordinates along polyline

...

initial named attributes of this object


Method custom()

Initialize a stream object representing a custom object with text

Usage

PDFDocument$custom(text, new_graphics_state = TRUE, ...)

Arguments

text

text string

new_graphics_state

Should the object be drawn in its own local graphics state? default: TRUE

...

initial named attributes of this object Initialize a new PDF Dict


Method dict()

Usage

PDFDocument$dict(...)

Arguments

...

named objects to add to dictionary


Method clone()

The objects of this class are cloneable with this method.

Usage

PDFDocument$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.