Skip to content

Getting Started ​

Install ​

jspdf, jspdf-autotable and marked are peer dependencies — the renderer draws into a jsPDF document you construct, so it uses the copy your project already has.

bash
npm install jspdf-md-renderer jspdf jspdf-autotable marked

First Render ​

ts
import { jsPDF } from 'jspdf'
import { MdTextRender } from 'jspdf-md-renderer'

const markdown = `
# My First PDF

This PDF was generated from **Markdown**.
`

const doc = new jsPDF({ unit: 'mm', format: 'a4', orientation: 'portrait', compress: true })

await MdTextRender(doc, markdown, {
  page: { margin: { top: 20, right: 20, bottom: 20, left: 20 } },
  font: { regular: { name: 'helvetica', style: 'normal' } },
})

doc.save('my-first-pdf.pdf')

That is a complete configuration. font.regular is the only value you must supply; the content area is derived from the document's own page size, and everything else has a default.

Smaller files with compress: true

jsPDF writes uncompressed content streams by default. compress: true makes it compress them, so the pages render the same but the file is much smaller — roughly 5× on a text-heavy document (fixtures from issue #77 rendered ten times across 45 pages: ~114 KB instead of ~555 KB).

Upgrading from 4.2 or earlier

Earlier versions required cursor, endCursorYHandler, font.bold, font.light and five separate page geometry fields. They all still work and still take precedence, so nothing needs changing. See Page Geometry for the mapping.

Check What Rendered ​

MdTextRender resolves to a summary of the render. An image that failed to load or content dropped by a security limit shows up here rather than only in the console:

ts
const result = await MdTextRender(doc, markdown, options)

console.log(result.pageCount, 'page(s), ended at Y', result.endY)

if (result.warnings.length) {
  console.warn('rendered with warnings:', result.warnings)
}

See Render Result.

Next Steps ​

Released under the MIT License.