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

@terraza/pdf

v0.1.0

Published

Markdown-to-PDF rendering for Terraza apps. Headless Chromium via Playwright, PDF metadata injection via pdf-lib.

Readme

@terraza/pdf

Markdown-to-PDF rendering for Terraza apps. Uses headless Chromium via Playwright for layout and pdf-lib for metadata injection.

The package is pure rendering — no database, no storage, no app coupling. Consumers bring their own markdown and CSS strings and do whatever they like with the returned bytes.

Install

pnpm add @terraza/pdf
npx playwright install chromium

Chromium is downloaded once by Playwright; subsequent builds reuse the cached binary.

Usage

import { renderMarkdownToPdf } from "@terraza/pdf";
import { writeFileSync } from "node:fs";

const css = `
  body { font-family: "IBM Plex Sans", sans-serif; }
  h1 { color: #E94B1C; }
`;

const bytes = await renderMarkdownToPdf("# Hello\n\nThis is **bold**.", {
  css,
  metadata: {
    title: "Demo",
    author: "Ken Grafals",
    subject: "Example PDF",
    keywords: ["demo", "terraza"],
  },
  format: "Letter",
  margin: { top: "0.6in", bottom: "0.6in", left: "0.6in", right: "0.6in" },
});

writeFileSync("demo.pdf", bytes);

API

renderMarkdownToPdf(markdown, options?) → Promise<Buffer>

Parses markdown (GFM enabled), wraps it in a minimal HTML document, renders via Chromium, and injects PDF metadata.

Options:

  • css (string) — inline CSS injected into a <style> tag in the HTML wrapper.
  • metadata (PdfMetadata) — title, author, subject, keywords, creator, producer. All optional. keywords may be an array or a comma-separated string.
  • format (PdfPageFormat) — page size. Default "Letter".
  • margin (PdfMargin) — top/bottom/left/right. Default "0.6in" all around.
  • wrapHtml (function) — override the HTML wrapper entirely. Receives (body, metadata, css) and returns the full HTML document string.

renderHtmlToPdf(html, options?) → Promise<Buffer>

Lower-level: takes a complete HTML document (no markdown parsing, no wrapper). Useful when the consumer already has rendered HTML or wants full control over the <head>.

Accepts the same options as renderMarkdownToPdf minus css and wrapHtml.

Combining with Shelf (example)

The package has no Shelf dependency, but here's the typical integration — a caller reads markdown + CSS from Shelf, renders, and stores the PDF back:

import { renderMarkdownToPdf } from "@terraza/pdf";
import { readDocument, storeDocument } from "@terraza/shelf-core";

const { document: md } = await readDocument(shelfDb, userId, "my-app/report.md");
const { document: css } = await readDocument(shelfDb, userId, "my-app/style.css").catch(() => ({ document: { body: "" } }));

const bytes = await renderMarkdownToPdf(md.body!, {
  css: css.body ?? "",
  metadata: { title: "Q1 Report", author: "Ken Grafals" },
});

await storeDocument(shelfDb, {
  userId,
  path: "my-app/report.pdf",
  content: bytes,
  editedBy: "my-app-mcp",
});

Testing

pnpm --filter @terraza/pdf test

Tests require Chromium installed via Playwright (npx playwright install chromium). Each test launches a real browser, so the suite takes a few seconds.