Skip to content

Options Reference

The RenderOption type controls every aspect of the markdown-to-PDF rendering. This page documents every field, its type, default value, and behavior.

Quick Example

ts
import type { RenderOption } from 'jspdf-md-renderer'

const options: RenderOption = {
  cursor: { x: 10, y: 10 },
  page: {
    format: 'a4',
    orientation: 'portrait',
    maxContentWidth: 190,
    maxContentHeight: 277,
    lineSpace: 1.5,
    defaultLineHeightFactor: 1.2,
    defaultFontSize: 12,
    defaultTitleFontSize: 14,
    topmargin: 10,
    xpading: 10,
    xmargin: 10,
    indent: 10,
  },
  font: {
    bold: { name: 'helvetica', style: 'bold' },
    regular: { name: 'helvetica', style: 'normal' },
    light: { name: 'helvetica', style: 'light' },
  },
  endCursorYHandler: (y) => console.log('End Y:', y),
}

Cursor

Starting position for the render cursor.

FieldTypeDefaultDescription
cursor.xnumber(required)X position where rendering starts (in page units)
cursor.ynumber(required)Y position where rendering starts (in page units)

Page

Controls page layout, spacing, and dimensions.

FieldTypeDefaultDescription
page.formatstring | number[]'a4'jsPDF page format (e.g., 'a4', 'letter', [width, height])
page.unitstringUnit system: 'mm', 'pt', 'px', 'in'
page.orientationstring'p'Page orientation: 'p' / 'portrait' or 'l' / 'landscape'
page.maxContentWidthnumber190Maximum width of the content area (in page units)
page.maxContentHeightnumber277Maximum height before triggering a page break
page.lineSpacenumber1.5Vertical spacing between rendered elements
page.defaultLineHeightFactornumber1.2Multiplier applied to font size for line height
page.defaultFontSizenumber12Base font size for body text
page.defaultTitleFontSizenumber14Font size used for heading elements
page.topmarginnumber10Top margin applied when content continues on a new page
page.xpadingnumber10Horizontal padding inside the content area
page.xmarginnumber10Left margin from the page edge
page.indentnumber10Indentation size for nested lists (multiplied by nesting level)

Font

Font configuration for different text weights.

FieldTypeDefaultDescription
font.bold.namestring'helvetica'Font family name for bold text
font.bold.stylestring'bold'Font style for bold text
font.regular.namestring'helvetica'Font family name for regular text
font.regular.stylestring'normal'Font style for regular text
font.light.namestring'helvetica'Font family name for light text
font.light.stylestring'light'Font style for light text

Custom Fonts

To use custom fonts, first register them with jsPDF using doc.addFont(), then reference them in the font config:

ts
doc.addFont('MyFont-Regular.ttf', 'MyFont', 'normal')
doc.addFont('MyFont-Bold.ttf', 'MyFont', 'bold')

const options = {
  font: {
    bold: { name: 'MyFont', style: 'bold' },
    regular: { name: 'MyFont', style: 'normal' },
    light: { name: 'MyFont', style: 'normal' },
  },
  // ...
}

Content optional

Text layout options.

FieldTypeDefaultDescription
content.textAlignmentstringText alignment: 'left', 'right', 'center', or 'justify'

Codespan optional

Styling for inline code (`code`) elements.

FieldTypeDefaultDescription
codespan.backgroundColorstring'#EEEEEE'Background color for inline code
codespan.paddingnumber0.5Padding around inline code text (in page units)
codespan.showBackgroundbooleantrueWhether to draw the background rectangle
codespan.fontSizeScalenumber0.9Scale factor applied to font size for code text

Link rendering options.

FieldTypeDefaultDescription
link.linkColor[number, number, number]RGB color tuple for link text (e.g., [0, 0, 255])

Table optional

Options passed directly to jspdf-autotable. See the autotable docs for all available options.

ts
{
  table: {
    theme: 'grid',           // 'striped' | 'grid' | 'plain'
    headStyles: { fillColor: [99, 102, 241] },
    styles: { fontSize: 10 },
    margin: { left: 10, right: 10 },
  }
}

Image optional

Default image rendering options.

FieldTypeDefaultDescription
image.defaultAlignstring'left'Default alignment for images: 'left', 'center', or 'right'

Per-Image Overrides

Individual images can override the default alignment using the attribute syntax:

markdown
![photo](url){width=200 align=center}

See Images for full details.

Callbacks

FieldTypeDefaultDescription
endCursorYHandler(y: number) => void(required)Called after rendering completes with the final Y cursor position
pageBreakHandler(doc: jsPDF) => voidCalled each time a new page is added during rendering

endCursorYHandler

This callback is required. It provides the Y position where rendering ended, enabling you to append more content below the markdown:

ts
let endY = 0
await MdTextRender(doc, md, {
  ...options,
  endCursorYHandler: (y) => { endY = y },
})
doc.text('Footer text', 10, endY + 10)

pageBreakHandler

Optional callback fired when a page break occurs. Use it to add headers, footers, or watermarks to new pages:

ts
await MdTextRender(doc, md, {
  ...options,
  pageBreakHandler: (doc) => {
    doc.setFontSize(8)
    doc.text('Page Header', 10, 5)
  },
})

TypeScript Type Definition

For reference, here is the complete RenderOption type:

ts
type RenderOption = {
  cursor: { x: number; y: number }
  page: {
    format?: string | number[]
    unit?: 'mm' | 'pt' | 'px' | 'in'
    orientation?: 'portrait' | 'p' | 'landscape' | 'l'
    maxContentWidth: number
    maxContentHeight: number
    lineSpace: number
    defaultLineHeightFactor: number
    defaultFontSize: number
    defaultTitleFontSize: number
    topmargin: number
    xpading: number
    xmargin: number
    indent: number
  }
  font: {
    bold: { name: string; style: string }
    regular: { name: string; style: string }
    light: { name: string; style: string }
  }
  content?: { textAlignment: 'left' | 'right' | 'center' | 'justify' }
  codespan?: {
    backgroundColor?: string
    padding?: number
    showBackground?: boolean
    fontSizeScale?: number
  }
  link?: { linkColor: [number, number, number] }
  table?: UserOptions  // from jspdf-autotable
  image?: { defaultAlign?: 'left' | 'center' | 'right' }
  pageBreakHandler?: (doc: jsPDF) => void
  endCursorYHandler: (y: number) => void
}

Released under the MIT License.