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.
npm install jspdf-md-renderer jspdf jspdf-autotable markedFirst Render
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' })
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.
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:
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
- Basic Usage — the full workflow and common options
- Page Geometry — margins, formats and orientation
- Render Result — warnings and what they mean
- Component Overrides — draw any block yourself
- Options Reference
- Security Guide
- Playground