pdf-lib cheat sheet

Posted Wednesday, November 5, 2025 by Sri. Tagged MEMO, CHEATSHEET

I’m using the pdf-lib Javascript library to generate PDF files, but the API reference material is not very good for getting a sense of what the library can do at-a-glance. This is my reference cheat sheet (WIP)

PDFPage Drawing Operations

Access these through calls like page.drawCircle({x:10, y:10, size:100})

Shared Options

all operators

opacity, blendMode

shape fill

color

shape stroke

borderWidth, borderColor

shape stroke styles

borderDashArray, borderDashPhase, borderLineCap

Drawing Operations

drawCircle(opt)

{ x, y, size }

drawSquare(opt)

{ x, y, size }

drawRectangle(opt)

{ x, y, xSkew, ySkew, width, height }

drawSvgPath( svgPath, opt )

{ x, y, scale, rotate }

drawLine(opt)

{ x, y, opacity, blendMod, start, end, thickness, dashArray, dashPhase, lineCap }

drawEllipse(opt)

{ x, y, xScale, yScale, rotate }

drawImage(pdfImage, opt)

{ x, y }

drawPage(embeddedPage, opt)

{ x, y, xScale, yScale, width, height, rotate, xSkew, ySkew }

drawText(textString, opt)

{ x, y, font, size, color, rotate, xSkew, ySkew, lineHeight, maxWidth, wordBreaks }

PDFPage Object Metrics

Used to get or set information about an object’s’ position, scale, or rotation. Also retrieve bounding box information and applying elative positioning.

Box Getters/Setters

getArtBox

getBleedBox

getCropBox

getMediaBox

getTrimBox

setArtBox

setBleedBox

setCropBox

setMediaBox

setTrimBox

Dimension Getters/Setters

getHeight

getWidth

getSize

setHeight

setWidth

setSize

Position Getters

getPosition

getX

getY

Relative Positioning

moveDown

moveLeft

moveRight

moveTo

moveUp

resetPosition

Transformations

scale

scaleAnnotations

scaleContent

translateContent

getRotation

setRotation

PDFPage Font State

Font State

setFont

setFontColor

setFontSize

setLineHeight

Low-level Factory Methods

pushOperators

create

of