npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@formepdf/preview

v0.25.0

Published

In-browser PDF preview for Forme — renders HTML through the same engine as the server and shows the actual PDF, so preview and output agree by construction.

Readme

@formepdf/preview

In-browser PDF preview for Forme. It renders your HTML through the same engine your server uses and shows the actual PDF in an iframe — so the preview and the produced file agree by construction, not by approximation.

import { FormePreview, standardFonts } from '@formepdf/preview';

// The SAME options object you pass to your server's renderHtml.
const options = { fonts: standardFonts() };

<FormePreview html={html} options={options} style={{ height: 600 }} />

Read this first: bundle cost

This component renders in the browser, which means it loads the Forme WASM engine — ~7.7 MB, fetched on first preview (lazily, so it's not in your initial bundle; cached by the browser thereafter). That is the unavoidable cost of rendering-in-browser: it's what buys you a preview that can't disagree with your server. If you only need to show a server-produced PDF and don't need live in-browser rendering, you don't need this package — point an <iframe> at your server's PDF.

Why it agrees with your output

Three things could make a preview diverge from the produced PDF. This component closes all three:

  • Display. It shows the real PDF bytes in the browser's native viewer (blob → iframe) — no canvas rasterizer approximating the file. What you see is the file, in the same viewer your recipient opens.
  • Options. There is no previewOptions. You pass the same options object to <FormePreview> and to your server's renderHtml. One configuration can't drift from itself.
  • Fonts. See below — the one that bites silently.

The font-parity contract

The silent failure: a template references a font the server embeds but the preview doesn't, so each side renders differently with no error. Forme's browser render path cannot fetch fonts — it takes bytes — so:

  1. Express fonts as bytes, once, for both sides. Use standardFonts() for the embeddable base-14 replacements, or pass your own { family, data: Uint8Array | base64, weight, italic }. Hand the same array to your server renderHtml and to <FormePreview options>.

  2. Make a mismatch loud. Fingerprint what the server was given and pass it in; the preview shows a banner if the fonts it holds don't match:

    import { fontFingerprint } from '@formepdf/preview';
    const print = fontFingerprint(options.fonts);   // compute where you build server options
    <FormePreview html={html} options={options} expectedFontFingerprint={print} />

Bundler setup

The engine is self-instantiating WASM, so your bundler needs WASM + top-level await support. For Vite, add vite-plugin-wasm and target esnext (which emits native top-level await):

// vite.config.ts
import { defineConfig } from 'vite';
import wasm from 'vite-plugin-wasm';

export default defineConfig({
  plugins: [wasm()],
  build: { target: 'esnext' },
  optimizeDeps: { esbuildOptions: { target: 'esnext' } },
});

You can instead add vite-plugin-top-level-await, but it bundles @swc/core and can break on some SWC versions — the esnext target is the more robust route. (Framework equivalents exist for webpack/Next/etc.)

Props

| Prop | Type | Notes | |---|---|---| | html | string | The document HTML — same string you render server-side. | | options | RenderHtmlOptions | The same object you pass to the server. Keep it referentially stable (memoize). | | expectedFontFingerprint | string? | Server's fontFingerprint(fonts); shows a banner on mismatch. | | debounceMs | number? | Debounce before re-render (default 150ms), for live-edit. | | onWarnings | (warnings: string[]) => void | Engine warnings (missing PDF/UA fonts, dropped content, …) — never silent. | | onError / onRender | callbacks | Error, and { passes, warnings, bytes } on success. | | className / style / title | — | Sizes and labels the iframe container. |

What it does NOT do

Not an editor. Not an annotating or form-filling viewer. Not a replacement for a full PDF viewer, and no toolbar of its own — you get the browser's native PDF controls (scroll, zoom, print). It renders the HTML and shows the file, pages in order. If you need programmatic zoom or custom page layout, that's a canvas-based viewer (a documented approximation) — out of scope for a fidelity-first component.

Notes & caveats

  • v1 is the HTML input path. JSX/React-element input is planned as a second input; the display and parity story are identical.
  • blob: under a strict CSP needs frame-src blob:.
  • Environments without a native PDF viewer (some embedded webviews) won't display the iframe; use onRender's bytes to offer a download instead.

MIT.