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 Operations

Drawing Operations

  • all operators: opacity and blendMode
  • shape operators: color, borderColor, borderWidth, borderDashArray, borderDashPhase, borderLineCap

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 }

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

...

Font State

setFont

...

setFontColor

...

setFontSize

...

setLineHeight

...

Low-level Factory Methods

pushOperators

...

create

...

of

...