Generate and preview PDFs directly in the browser
@bonniepdf/core runs entirely in the browser (~296 KB gzipped, zero dependencies). Build a document from tables, text, SVG logos, and charts, preview it in the page as crisp vector SVG, and hand the user a real, selectable, tagged PDF—with no server round-trip, no WASM binary, and no headless Chromium.
Build a PDF on the client and trigger a download
In a browser application—React, Vue, Svelte, Angular, or plain TypeScript—generateBytesAsync() returns a Uint8Array of PDF bytes. Wrap it in a Blob to open it in a new tab or download it immediately. Sensitive data already on the screen never has to be uploaded to a rendering service just to turn it into a PDF.
import { AccessibilityMode, Document, Heading, settings, Table, TextBlock } from '@bonniepdf/core'
settings.license = 'evaluation' // your licence tier, declared once at startup
const doc = new Document({
settings: { language: 'en-GB', accessibility: AccessibilityMode.PdfUa1 },
metadata: { title: 'Order Summary #4821', author: 'Acme Corp' },
})
doc.add(new Heading('Order Summary #4821', { level: 1 }))
const table = new Table({ columns: [3, 1, 1], cellPadding: 6 })
table.addHeader('Item', 'Qty', 'Total')
table.addRow('Annual subscription', '1', '£240.00')
doc.add(table)
doc.add(new TextBlock('Generated in the browser with no server request.'))
const bytes = await doc.generateBytesAsync()
const url = URL.createObjectURL(new Blob([bytes.buffer as ArrayBuffer], { type: 'application/pdf' }))
const link = document.createElement('a')
link.href = url
link.download = 'order-4821.pdf'
link.click()
URL.revokeObjectURL(url)Subpath exports (@bonniepdf/core/charts, /qr, /datamatrix, /security) keep unused capabilities out of your application bundle. See the TypeScript bundle size breakdown.
Instant vector previews with <bonnie-pdf-previewer>
Before downloading, users often want to see the finished pages. Because BonniePDF measures and positions every glyph itself, it can export each page as a standalone vector SVG from the exact same layout pass. The @bonniepdf/previewer package renders those pages inside an isolated Shadow-DOM web component with zoom, thumbnails, and on-demand PDF download:
import '@bonniepdf/previewer/element' // registers <bonnie-pdf-previewer>
const viewer = document.querySelector('bonnie-pdf-previewer')!
await viewer.load(doc) // renders vector SVG pages; generates the PDF on DownloadEvery example on this website runs that way in your browser right now—open any document in the examples gallery to see it.
Real PDF layout without a rendering server
Built for web apps that need proper pagination and selectable text without running Chromium in the cloud.
~296 KB gzipped
Data stays in the tab
True pagination
Shadow-DOM previewer
@bonniepdf/previewer displays vector SVG pages at any zoom level with host CSS isolated.Web Worker ready
Tagged PDF/UA & PDF/A
Frequently asked questions
Does browser PDF generation need a backend or WASM binary?
No. @bonniepdf/core is pure TypeScript (~296 KB gzipped for the full entry) with zero runtime dependencies. It writes the PDF byte stream directly in JavaScript and uses the browser’s built-in SubtleCrypto when AES-256 encryption is enabled.
How is this different from html2canvas or window.print()?
Screenshot tools rasterise DOM nodes into a bitmap image inside a PDF, so text cannot be selected or searched, files are large, and multi-page tables slice through rows. Browser print stylesheets depend on the user’s browser and print dialog settings. BonniePDF lays out real vector text, tables, and charts from a document model, repeats table headers across page breaks, and emits tagged PDF/UA and PDF/A output.
Can users preview the document before downloading?
Yes. doc.generateSvgDocumentAsync() exports each page as a vector SVG from the same layout pass, and @bonniepdf/previewer wraps those pages in a Shadow-DOM web component (<bonnie-pdf-previewer>) with zoom, page thumbnails, and an optional accessibility inspector.
Can it run in a Web Worker?
Yes. Core touches no DOM APIs, so you can build and render large multi-page reports inside a Web Worker and post the resulting Uint8Array or SVG export back to the main thread without blocking the UI.
When should I generate on the server instead?
Generate on the server when the document relies on secrets or private data the client must not receive, when files must be digitally signed with a server certificate or archived centrally, or when sending jobs in background batches. The same @bonniepdf/core code (or BonniePDF on .NET) runs on the server unchanged.