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

  1. Render markdown to Uint8Array with renderPdf().
  2. Call mount(container, bytes) — creates a Blob URL and embeds it (for example in an <iframe> or <object>).
  3. 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

ApproachUse when
mount()Live preview in an editor or report studio
renderPdfToFile()Server export or CLI
Raw bytesAttach to email, upload to storage, or pipe to another API

See Usage for the full render API.

Copyright © 2026