Guide
Browser preview
Mount PDF bytes in the DOM with comark-pdf/preview and revoke Blob URLs when done.
Use comark-pdf/preview to show PDF bytes in the browser without writing a file.
import { renderPdf } from 'comark-pdf'
import { mount } from 'comark-pdf/preview'
const bytes = await renderPdf(markdownString)
const handle = mount(document.getElementById('preview'), bytes)
// Later, to free the Blob URL:
handle.revoke()
Typical flow
- Render markdown to
Uint8ArraywithrenderPdf(). - Call
mount(container, bytes)— creates a Blob URL and embeds it (for example in an<iframe>or<object>). - Call
handle.revoke()when the preview is removed to release the Blob URL.
Preview mounts bytes only. It does not re-parse markdown. Re-render when the source changes.
When to use preview vs download
| Approach | Use when |
|---|---|
mount() | Live preview in an editor or report studio |
renderPdfToFile() | Server export or CLI |
Raw bytes | Attach to email, upload to storage, or pipe to another API |
See Usage for the full render API.