Skip to content
Jennifer Programming Language

pdf API reference

Generate PDF documents - text, lines, rectangles - the way html / label generate their formats. Build a Document of Pages with value-semantic builders, then render() writes the PDF object / xref structure by hand (no stdlib PDF) as bytes. Content streams are FlateDecode-compressed via compress. Two font paths: the standard-14 Type1 fonts (Helvetica / Times / Courier families + Symbol / ZapfDingbats) via text, and embedded TrueType fonts via loadFont / addFont / textUnicode - a Type0 / CIDFontType2 composite (Identity-H) with an embedded FontFile2 and a ToUnicode map, so any script the font covers (accented Latin, Greek, Cyrillic, CJK, ...) renders and stays selectable. Raster images embed as image XObjects via loadImage / addImage / drawImage - PNG (greyscale / RGB / palette, plus 8-bit alpha as a soft mask), JPEG (DCTDecode), and anything else the images library decodes (interlaced or tRNS PNG, 16-bit alpha, GIF); imageFrom embeds an images.Image directly. Text layout - measureText width measurement (standard-14 AFM metrics + embedded-font advances), wrapText word-wrap, and textBlock wrapped / aligned paragraphs (left / right / center / justify) - flows text into a column. Object numbers are assigned dynamically. Pure Jennifer (over the font module and the images library); both binaries.

Coordinates are in PDF points (1/72 inch), origin bottom-left, y upward. Common page sizes: US Letter 612 x 792, A4 595 x 842. Colours are 0-255 RGB.

Import with import "pdf.j" as pdf;. See the pdf guide for prose and examples.

Contents

NameWhat it is
addFontA copy of the document with an embedded font registered, so render writes its font program and dictionaries.
addFontsRegister several embedded fonts at once, in order: the batch form of addFont, one crossing for the whole ...
addImageA copy of the document with an embedded image registered, so render writes its image XObject.
addImagesRegister several images at once, in order: the batch form of addImage.
addPageA copy of the document with a page appended.
addPagesAppend several pages at once, returning the updated document.
bookmarkA copy of the document with one outline (bookmark) entry appended (value-semantic).
bookmarksAppend several outline (bookmark) entries at once, in order: the batch form of bookmark, with the same ne...
colorSet the fill and stroke colour (0-255 RGB) for subsequent drawing on the page.
documentAn empty document.
drawApply a list of DrawOps to a page in order, returning the updated page.
drawImageDraw a registered image scaled into the rectangle at (x, y) of the given width and height (points).
foldLineHard-fold one line so every piece fits maxWidth (points).
getCurrentPageNrThe 1-based number of the page currently being built - the next page to be added, i.e.
getTotalPagesThe total number of pages added to the document (the value {pages} expands to).
imageFromTurn an images.Image into an embeddable image under a resource name, so a picture built or edited with th...
infoA copy of the document with one metadata field set (value-semantic).
lineDraw a straight line from (fromX, fromY) to (toX, toY).
linkAdd a link annotation: a clickable rectangle (lower-left x, y, plus width / height, in PDF points) ...
loadFontLoad an embeddable font from its bytes, under a resource name used to select it in textUnicode.
loadImageLoad a raster image (PNG, JPEG or GIF) from its bytes, under a resource name used to select it in drawImage.
measureTextMeasure the rendered width (in points) of a string in a standard-14 font at a point size, using the Adobe C...
measureTextUnicodeMeasure the rendered width (in points) of a string in an embedded font at a point size, using the font's ow...
pageA blank page of the given size in points (e.g.
pageLabelA blank page label (empty slots, Helvetica 9pt, 36-point margin, no border, black).
pdfDateFormat an instant as a PDF date string (D:YYYYMMDDHHmmSS+HH'mm'), for use as a CreationDate / ModDate...
rectDraw a rectangle at (x, y) of the given size.
renderRender the document to PDF bytes (PDF 1.7).
setFooterAttach a running footer, drawn on every page when the document renders.
setHeaderAttach a running header, drawn on every page when the document renders.
textDraw a line of text at (x, y) in the given standard-14 font and point size.
textBlockFlow standard-14 text into a column: word-wrap str to width points and draw each line, the first line's...
textBlockUnicodeFlow embedded-font (Unicode) text into a column - textBlock for a font from loadFont / addFont.
textGlyphsDraw glyphs of an embedded font at (x, y) by glyph id, for a caller that has already mapped its text throug...
textUnicodeDraw Unicode text at (x, y) in an embedded font (from loadFont + addFont) at the given point size.
toWinAnsiReturn s with every character the standard-14 fonts cannot encode (outside WinAnsi / windows-1252) replac...
wrapTextWord-wrap a standard-14 string to a maximum line width (points), returning the lines.
wrapTextUnicodeWord-wrap an embedded-font string to a maximum line width (points).
Documentstruct: A PDF document: an ordered list of pages, the document metadata (the PDF Info dictionary, keyed by PDF key ...
GlyphUsestruct: A record of one glyph used by embedded text: which font, its glyph id, and the Unicode codepoint it came fr...
Imagestruct: A loaded raster image (from loadImage), ready to embed as a PDF image XObject and draw with drawImage.
LinkAnnotstruct: A link annotation: a clickable rectangle on a page that opens a URI.
LoadedFontstruct: A loaded, embeddable font: a resource name (referenced in textUnicode) and the parsed font.Font.
OutlineEntrystruct: One outline (bookmark) entry: a title that jumps to a position on a page, plus the heading level that nests...
Pagestruct: A single page: its size (points), its accumulated content-stream operators, and its link annotations.
PageLabelstruct: A running header or footer, drawn on every page at render time.
DrawOpenum: One drawing operation for the batch draw, mirroring the per-op functions: Text (a standard-font string,...

Functions

addFont

jennifer
pdf.addFont(doc as Document, lf as LoadedFont)

A copy of the document with an embedded font registered, so render writes its font program and dictionaries.

doc
the document
lf
the loaded font (from loadFont)
Returns Document
a fresh document with the font registered

addFonts

jennifer
pdf.addFonts(doc as Document, lfs as list of LoadedFont)

Register several embedded fonts at once, in order: the batch form of addFont, one crossing for the whole list.

doc
the document
lfs
the loaded fonts (from loadFont)
Returns Document
a fresh document with the fonts registered

addImage

jennifer
pdf.addImage(doc as Document, img as Image)

A copy of the document with an embedded image registered, so render writes its image XObject. Draw it on a page with drawImage.

doc
the document
img
the loaded image (from loadImage)
Returns Document
a fresh document with the image registered

addImages

jennifer
pdf.addImages(doc as Document, imgs as list of Image)

Register several images at once, in order: the batch form of addImage. addImage copies the whole document, every image registered before included, on each call, so registering N images one call at a time is O(N^2); collect them into a list of Image and register them with one call.

doc
the document
imgs
the loaded images (from loadImage / imageFrom)
Returns Document
a fresh document with the images registered

addPage

jennifer
pdf.addPage(doc as Document, pg as Page)

A copy of the document with a page appended.

doc
the document
pg
the page to add
Returns Document
a fresh document with the page appended

addPages

jennifer
pdf.addPages(doc as Document, pgs as list of Page)

Append several pages at once, returning the updated document. addPage copies the whole document (every prior page's content streams included) on each call, so building an N-page document with addPage in a loop is O(N^2); collect the pages into a list of Page and attach them with one addPages call to stay linear.

doc
the document to extend
pgs
the pages to append, in order
Returns Document
a new document with the pages appended

bookmark

jennifer
pdf.bookmark(
    doc as Document,
    page as int,
    y as int,
    title as string,
    level as int)

A copy of the document with one outline (bookmark) entry appended (value-semantic). Entries are nested by level in the order added: a level-2 entry becomes a child of the most recent level-1, and so on. The destination scrolls page page (0-based) so that y (PDF points, origin bottom-left) is at the top of the view. With any outline present, the viewer opens showing the bookmark panel.

doc
the document
page
the 0-based index of the destination page
y
the destination y in PDF points
title
the bookmark label
level
the nesting level (>= 1)
Returns Document
a copy with the entry appended
Throws Error
kind "pdf" for a level below 1 or a negative page; render throws "pdf" for a page index past the document's last page

bookmarks

jennifer
pdf.bookmarks(doc as Document, entries as list of OutlineEntry)

Append several outline (bookmark) entries at once, in order: the batch form of bookmark, with the same nesting and checks. Each bookmark call copies the whole document (its pages, images and the outline so far) to cross into the module, so a long outline added one entry at a time costs O(entries^2); collect the entries into a list of OutlineEntry and add them with one call.

doc
the document
entries
the entries, in document order
Returns Document
a copy with the entries appended
Throws Error
kind "pdf" for an entry with a level below 1 or a negative page (nothing is appended); render throws "pdf" for a page index past the document's last page

color

jennifer
pdf.color(pg as Page, red as int, green as int, blue as int)

Set the fill and stroke colour (0-255 RGB) for subsequent drawing on the page.

pg
the page
red
the red component 0-255
green
the green component 0-255
blue
the blue component 0-255
Returns Page
a fresh page with the colour set
Throws Error
kind "pdf" for a component outside 0-255

document

jennifer
pdf.document()

An empty document. The Producer metadata defaults to "Jennifer pdf"; everything else is unset (no CreationDate is stamped, so output stays deterministic - set one explicitly with info + pdfDate if you want it).

Returns Document
the document

draw

jennifer
pdf.draw(pg as Page, ops as list of DrawOp)

Apply a list of DrawOps to a page in order, returning the updated page. This is the batch form of the per-op draw functions (text / textUnicode / line / rect / color / drawImage / link) and produces byte-identical output to calling them one after another. Prefer it when emitting many elements (table cells, a long run of lines or text): each per-op call extends the page's content stream by string concatenation, which copies it, so a loop of them is O(ops^2) (and, outside a function or inside a try, copies the whole page as well), whereas draw collects every op's content and joins it once, which is O(ops). A Color op sets the colour for the ops after it, exactly as a color call would. Image ops reference an image you have already registered on the document with addImage.

pg
the page to draw onto
ops
the operations to apply, in order
Returns Page
a copy of the page with every op applied
Throws Error
kind "pdf" for a Text op whose font is not a standard-14 name
Throws Error
kind "pdf" for a character outside WinAnsi

drawImage

jennifer
pdf.drawImage(
    pg as Page,
    img as Image,
    x as int,
    y as int,
    width as int,
    height as int)

Draw a registered image scaled into the rectangle at (x, y) of the given width and height (points). The image keeps no aspect ratio of its own - it fills the box - so pass a width / height in the image's own proportion to avoid stretching. addImage the image into the document first so the resource name resolves.

pg
the page
img
the image (from loadImage)
x
the lower-left x in points
y
the lower-left y in points
width
the drawn width in points
height
the drawn height in points
Returns Page
a fresh page with the image drawn

foldLine

jennifer
pdf.foldLine(font as string, size as int, text as string, maxWidth as int)

Hard-fold one line so every piece fits maxWidth (points). Breaks at the last space or seam punctuation before the overflow, or mid-token when there is none (a bare URL, a slash-joined identifier). Unlike wrapText, it does not reflow on every space - it only breaks where a line would otherwise run past the box - so it is the right tool for a code line or an unbreakable token that must stay on the page. A single character wider than maxWidth is emitted alone.

font
the standard-14 font
size
the point size
text
the line to fold (no embedded newlines)
maxWidth
the target width in points
Returns list of string
the fitted pieces (at least one)
Throws Error
kind "pdf" for a width that is not positive

getCurrentPageNr

jennifer
pdf.getCurrentPageNr(doc as Document)

The 1-based number of the page currently being built - the next page to be added, i.e. getTotalPages(doc) + 1. Use it while filling a page (before addPage) to label it.

doc
the document
Returns int
the current page number

getTotalPages

jennifer
pdf.getTotalPages(doc as Document)

The total number of pages added to the document (the value {pages} expands to).

doc
the document
Returns int
the page count

imageFrom

jennifer
pdf.imageFrom(name as string, img as images.Image)

Turn an images.Image into an embeddable image under a resource name, so a picture built or edited with the images library (cropped, resized, composited) goes into the PDF without being encoded to PNG and parsed again. The pixels embed as an RGB colour stream, plus an alpha soft mask when any pixel is not fully opaque. Register it with addImage, then drawImage it.

name
the resource name (e.g. "Chart"; letters / digits)
img
the image
Returns Image
the embeddable image

info

jennifer
pdf.info(doc as Document, key as string, value as string)

A copy of the document with one metadata field set (value-semantic). key is a PDF Info key - "Title", "Author", "Subject", "Keywords", "Creator", "Producer", "CreationDate", "ModDate" (or any custom key).

doc
the document
key
the Info-dictionary key
value
the value
Returns Document
a fresh document with the metadata set

line

jennifer
pdf.line(pg as Page, fromX as int, fromY as int, toX as int, toY as int)

Draw a straight line from (fromX, fromY) to (toX, toY).

pg
the page
fromX
the start x
fromY
the start y
toX
the end x
toY
the end y
Returns Page
a fresh page with the line added
jennifer
pdf.link(
    pg as Page,
    x as int,
    y as int,
    width as int,
    height as int,
    uri as string)

Add a link annotation: a clickable rectangle (lower-left x, y, plus width / height, in PDF points) that opens uri. The border is invisible, so place it over text drawn with text (measure the text width with measureText) to make that text a hyperlink - a footer backlink, a citation, a URL in prose.

pg
the page
x
lower-left x of the clickable rectangle
y
lower-left y of the clickable rectangle
width
rectangle width in points
height
rectangle height in points
uri
the URI the link opens
Returns Page
the page with the link recorded

loadFont

jennifer
pdf.loadFont(name as string, data as bytes)

Load an embeddable font from its bytes, under a resource name used to select it in textUnicode. The font is embedded (and its Unicode text made selectable) when the document renders.

name
the resource name (e.g. "Body"; letters / digits)
data
the TrueType (.ttf) font file
Returns LoadedFont
the loaded font

loadImage

jennifer
pdf.loadImage(name as string, data as bytes)

Load a raster image (PNG, JPEG or GIF) from its bytes, under a resource name used to select it in drawImage. The format is detected from the file signature. PNG greyscale / RGB / palette embeds directly with a FlateDecode predictor, and 8-bit greyscale+alpha / RGBA is split into a colour stream plus an alpha soft mask. JPEG (baseline / progressive greyscale / RGB / CMYK) embeds as-is via DCTDecode. Everything else - an interlaced PNG, a PNG with tRNS transparency or 16-bit alpha, a GIF (its first frame) - is decoded with the images library and embedded as RGB pixels, with a soft mask when any pixel is translucent.

name
the resource name (e.g. "Logo"; letters / digits)
data
the PNG, JPEG or GIF file
Returns Image
the loaded image
Throws Error
kind "pdf" if the data is not a supported image
Throws Error
kind "limit" if it is larger than images.decode's pixel cap

measureText

jennifer
pdf.measureText(font as string, size as int, str as string)

Measure the rendered width (in points) of a string in a standard-14 font at a point size, using the Adobe Core-14 AFM metrics. A character outside WinAnsi, or a Symbol / ZapfDingbats font, throws.

font
a standard-14 base font name
size
the font size in points
str
the text to measure
Returns float
the width in points
Throws Error
kind "pdf" for an unknown / metric-less font
Throws Error
kind "pdf" for a character outside WinAnsi

measureTextUnicode

jennifer
pdf.measureTextUnicode(lf as LoadedFont, size as int, str as string)

Measure the rendered width (in points) of a string in an embedded font at a point size, using the font's own glyph advances.

lf
the embedded font
size
the font size in points
str
the text to measure
Returns float
the width in points

page

jennifer
pdf.page(width as int, height as int)

A blank page of the given size in points (e.g. page(612, 792) for Letter, page(595, 842) for A4).

width
the page width in points
height
the page height in points
Returns Page
the page
Throws Error
kind "pdf" for a width or height that is not positive

pageLabel

jennifer
pdf.pageLabel()

A blank page label (empty slots, Helvetica 9pt, 36-point margin, no border, black). Copy it and set slots / options, then attach with setHeader / setFooter.

Returns PageLabel
the default label

pdfDate

jennifer
pdf.pdfDate(t as time.Time)

Format an instant as a PDF date string (D:YYYYMMDDHHmmSS+HH'mm'), for use as a CreationDate / ModDate value. Passing a time is explicit, so it does not make render non-deterministic on its own.

t
the instant
Returns string
the PDF date string

rect

jennifer
pdf.rect(
    pg as Page,
    x as int,
    y as int,
    width as int,
    height as int,
    filled as bool)

Draw a rectangle at (x, y) of the given size. filled fills it; otherwise it is stroked (outline only).

pg
the page
x
the lower-left x
y
the lower-left y
width
the width in points
height
the height in points
filled
true to fill, false to stroke
Returns Page
a fresh page with the rectangle added

render

jennifer
pdf.render(doc as Document)

Render the document to PDF bytes (PDF 1.7). Any running header / footer is drawn onto every page first. Content streams are FlateDecode-compressed; standard-14 fonts become shared Type1 objects and each embedded font a Type0 / CIDFontType2 with an embedded FontFile2 and a ToUnicode map. Registered images become image XObjects (with a soft-mask XObject when they carry alpha). An outline (bookmarks) is emitted when the document has any, with the catalog set to open the bookmark panel. Objects are numbered dynamically, so any mix of pages, fonts, images, and resources references correctly.

doc
the document to render
Returns bytes
the PDF file contents
Throws Error
kind "pdf" for a header / footer character outside WinAnsi
Throws Error
kind "pdf" for a document with no pages, or a bookmark whose page index is past the last page

setFooter

jennifer
pdf.setFooter(doc as Document, label as PageLabel)

Attach a running footer, drawn on every page when the document renders.

doc
the document
label
the footer spec
Returns Document
the document with the footer set

setHeader

jennifer
pdf.setHeader(doc as Document, label as PageLabel)

Attach a running header, drawn on every page when the document renders.

doc
the document
label
the header spec
Returns Document
the document with the header set

text

jennifer
pdf.text(
    pg as Page,
    x as int,
    y as int,
    font as string,
    size as int,
    str as string)

Draw a line of text at (x, y) in the given standard-14 font and point size.

pg
the page
x
the x position (points from the left)
y
the y position (points from the bottom)
font
a standard-14 base font name (e.g. "Helvetica")
size
the font size in points
str
the text to draw
Returns Page
a fresh page with the text added
Throws Error
kind "pdf" if the font is not a standard-14 name
Throws Error
kind "pdf" for a character outside WinAnsi

textBlock

jennifer
pdf.textBlock(
    pg as Page,
    x as int,
    y as int,
    width as int,
    font as string,
    size as int,
    leading as int,
    str as string,
    align as string)

Flow standard-14 text into a column: word-wrap str to width points and draw each line, the first line's baseline at (x, y) and each subsequent line leading points lower. align is "left" / "right" / "center" / "justify" (justify pads inter-word gaps on every line but the last of each paragraph). The drawn block is len(wrapText(...)) * leading points tall.

pg
the page
x
the column's left x in points
y
the first line's baseline y in points
width
the column width in points
font
a standard-14 base font name
size
the font size in points
leading
the line-to-line spacing in points
str
the text (newlines are hard breaks)
align
"left" / "right" / "center" / "justify"
Returns Page
a fresh page with the text block drawn
Throws Error
kind "pdf" for an unknown align or font
Throws Error
kind "pdf" for a character outside WinAnsi
Throws Error
kind "pdf" for a width that is not positive

textBlockUnicode

jennifer
pdf.textBlockUnicode(
    pg as Page,
    x as int,
    y as int,
    width as int,
    lf as LoadedFont,
    size as int,
    leading as int,
    str as string,
    align as string)

Flow embedded-font (Unicode) text into a column - textBlock for a font from loadFont / addFont. Same wrapping / alignment / leading behaviour.

pg
the page
x
the column's left x in points
y
the first line's baseline y in points
width
the column width in points
lf
the embedded font
size
the font size in points
leading
the line-to-line spacing in points
str
the text (newlines are hard breaks)
align
"left" / "right" / "center" / "justify"
Returns Page
a fresh page with the text block drawn
Throws Error
kind "pdf" for an unknown align
Throws Error
kind "pdf" for a width that is not positive

textGlyphs

jennifer
pdf.textGlyphs(
    pg as Page,
    x as int,
    y as int,
    font as string,
    size as int,
    gids as list of int,
    cps as list of int)

Draw glyphs of an embedded font at (x, y) by glyph id, for a caller that has already mapped its text through the font's cmap (with font.glyphIds) and measured it (with font.advances), and so need not hand the whole font over on every call. font is the resource name the font was loaded under (loadFont) and registered with (addFont); cps gives each glyph's source code point, for the font's ToUnicode map (copy and paste, search). The page records each distinct glyph once (textUnicode records every one drawn); the rendered PDF is the same bytes as with textUnicode for the same glyphs.

pg
the page
x
the x position (points from the left)
y
the y position (points from the bottom)
font
the embedded font's resource name
size
the font size in points
gids
the glyph ids, in drawing order
cps
the code point each glyph stands for, one per glyph
Returns Page
a fresh page with the glyphs added
Throws Error
kind "pdf" for a malformed resource name, a glyph id outside 0..65535, or cps not the same length as gids

textUnicode

jennifer
pdf.textUnicode(
    pg as Page,
    x as int,
    y as int,
    lf as LoadedFont,
    size as int,
    str as string)

Draw Unicode text at (x, y) in an embedded font (from loadFont + addFont) at the given point size. Each character maps through the font's cmap to a glyph, so any script the font covers - including CJK - renders and stays selectable / copyable in a viewer.

pg
the page
x
the x position (points from the left)
y
the y position (points from the bottom)
lf
the embedded font
size
the font size in points
str
the text to draw
Returns Page
a fresh page with the text added

toWinAnsi

jennifer
pdf.toWinAnsi(s as string, replacement as string)

Return s with every character the standard-14 fonts cannot encode (outside WinAnsi / windows-1252) replaced by replacement ("" drops it). A clean string (the common case) is returned unchanged after a single whole-string check, so the per-character path runs only when there is something to replace. This lets a caller keep one out-of-range glyph from aborting a whole render.

s
the text
replacement
the substitute for an un-encodable character
Returns string
the WinAnsi-safe text

wrapText

jennifer
pdf.wrapText(font as string, size as int, str as string, maxWidth as int)

Word-wrap a standard-14 string to a maximum line width (points), returning the lines. Existing newlines are honoured as hard breaks; runs of spaces collapse. A word-wrapped line still wider than the box (an unbreakable token) is hard-folded with foldLine, so no output line runs past maxWidth.

font
a standard-14 base font name
size
the font size in points
str
the text to wrap
maxWidth
the maximum line width in points
Returns list of string
the wrapped lines
Throws Error
kind "pdf" for an unknown / metric-less font
Throws Error
kind "pdf" for a character outside WinAnsi
Throws Error
kind "pdf" for a width that is not positive

wrapTextUnicode

jennifer
pdf.wrapTextUnicode(
    lf as LoadedFont,
    size as int,
    str as string,
    maxWidth as int)

Word-wrap an embedded-font string to a maximum line width (points).

lf
the embedded font
size
the font size in points
str
the text to wrap
maxWidth
the maximum line width in points
Returns list of string
the wrapped lines
Throws Error
kind "pdf" for a width that is not positive

Structs

Document

A PDF document: an ordered list of pages, the document metadata (the PDF Info dictionary, keyed by PDF key name - "Title", "Author", ...), any embedded fonts registered with addFont, any outline (bookmark) entries, and an optional running header / footer drawn on every page at render time.

jennifer
def struct Document {
    pages as list of Page,
    info as map of string to string,
    embedded as list of LoadedFont,
    images as list of Image,
    outline as list of OutlineEntry,
    header as PageLabel,
    footer as PageLabel,
    headerOn as bool,
    footerOn as bool
};
pages
the document's pages
info
the Info-dictionary metadata
embedded
the embedded fonts
images
the embedded raster images
outline
the outline / bookmark entries, in document order
header
the running header (drawn when headerOn)
footer
the running footer (drawn when footerOn)
headerOn
whether a header has been set
footerOn
whether a footer has been set

GlyphUse

A record of one glyph used by embedded text: which font, its glyph id, and the Unicode codepoint it came from - collected so render can build the font's width array and ToUnicode map.

jennifer
def struct GlyphUse {
    font as string,
    gid as int,
    cp as int
};
font
the font resource name
gid
the glyph id
cp
the source Unicode codepoint

Image

A loaded raster image (from loadImage), ready to embed as a PDF image XObject and draw with drawImage. Register it in a document with addImage.

jennifer
def struct Image {
    name as string,
    width as int,
    height as int,
    bits as int,
    colorSpace as string,
    filter as string,
    predictor as int,
    colors as int,
    decode as string,
    data as bytes,
    smask as bytes,
    hasSmask as bool
};
name
the resource name (referenced in drawImage)
width
the pixel width
height
the pixel height
bits
bits per colour component
colorSpace
the PDF colour-space token (e.g. "/DeviceRGB")
filter
the stream filter ("DCTDecode" for JPEG, "FlateDecode" for PNG)
predictor
15 when the FlateDecode stream carries PNG predictors, else 0
colors
colour components per pixel (for the predictor DecodeParms)
decode
an optional /Decode array token (Adobe CMYK JPEG), else ""
data
the image stream bytes
smask
the soft-mask (alpha) stream, empty when opaque
hasSmask
whether the image carries an alpha soft mask

LinkAnnot

A link annotation: a clickable rectangle on a page that opens a URI. The rect is given in PDF points by its lower-left corner and its size; the border is drawn invisibly, so only the underlying text (or graphic) shows.

jennifer
def struct LinkAnnot {
    x as int,
    y as int,
    width as int,
    height as int,
    uri as string
};
x
lower-left x of the clickable rectangle
y
lower-left y of the clickable rectangle
width
rectangle width in points
height
rectangle height in points
uri
the URI the link opens

LoadedFont

A loaded, embeddable font: a resource name (referenced in textUnicode) and the parsed font.Font. Register it in a document with addFont.

jennifer
def struct LoadedFont {
    name as string,
    f as font.Font
};
name
the resource name (e.g. "Body")
f
the parsed font

OutlineEntry

One outline (bookmark) entry: a title that jumps to a position on a page, plus the heading level that nests it under the outline tree. Built with bookmark.

jennifer
def struct OutlineEntry {
    title as string,
    page as int,
    y as int,
    level as int
};
title
the bookmark label
page
the 0-based page index the bookmark points at
y
the destination y coordinate in PDF points (origin bottom-left)
level
the nesting level (1 = top; a level-2 entry nests under the last level-1)

Page

A single page: its size (points), its accumulated content-stream operators, and its link annotations.

jennifer
def struct Page {
    width as int,
    height as int,
    content as string,
    fonts as list of string,
    glyphUses as list of GlyphUse,
    glyphSeen as map of string to bool,
    annots as list of LinkAnnot
};
width
the page width in points
height
the page height in points
content
the content-stream operators built so far
fonts
the distinct standard-14 fonts referenced on this page
glyphUses
embedded-font glyphs drawn on this page
glyphSeen
the font and glyph id pairs in glyphUses, kept by the drawing functions so a Glyphs op records each glyph once without rebuilding the set
annots
the page's link annotations

PageLabel

A running header or footer, drawn on every page at render time. Its three text slots are left- / centre- / right-aligned (alignment measured with the font's own metrics), and each may contain the placeholders %page% (the 1-based page number) and %pages% (the total page count), filled in per page - so a footer "sample.pdf" / "" / "%page%/%pages%" reads sample.pdf ... 13/108. The placeholders are percent-delimited (not braces) so they do not collide with Jennifer's own {expr} string interpolation. margin is the distance from the page edge to the text on every side. With border on, a thin rule is drawn under a header / over a footer.

jennifer
def struct PageLabel {
    left as string,
    center as string,
    right as string,
    font as string,
    size as int,
    margin as int,
    border as bool,
    red as int,
    green as int,
    blue as int,
    leftUri as string,
    centerUri as string,
    rightUri as string
};
left
left-aligned slot (may use %page% / %pages%)
center
centre-aligned slot
right
right-aligned slot
font
a standard-14 font name
size
the point size
margin
distance from the page edge, in points
border
draw a separating rule
red
text / rule colour red 0-255
green
text / rule colour green 0-255
blue
text / rule colour blue 0-255
leftUri
if set, makes the left slot a link to this URI ("" = none)
centerUri
if set, makes the centre slot a link to this URI ("" = none)
rightUri
if set, makes the right slot a link to this URI ("" = none)

Enums

DrawOp

One drawing operation for the batch draw, mirroring the per-op functions: Text (a standard-font string, like text), TextUnicode (an embedded-font string, like textUnicode), Line, Rect (stroked or filled), Color (sets the stroke + fill colour for subsequent ops), Image (draws a loaded image, like drawImage), Link (a URI rectangle, like link) and Glyphs (glyph ids already mapped in an embedded font, like textGlyphs). Build a list of these and apply them in order with draw, which builds the content stream once instead of once per op - so drawing N elements is O(N) rather than O(N^2).