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

@foldworks/pdf

v0.1.0

Published

Composable PDF page geometry, rendering, and overlay surface primitives for Foldkit.

Readme

@foldworks/pdf

PDF building blocks for Foldkit applications. This package contains no toolbar, annotation schema, or field semantics. Use it to compose a viewer, an annotation editor, a review surface, or another PDF interface.

| Primitive | Purpose | | ------------------ | --------------------------------------------------------------------------- | | readPdfPages | Read each page's visible crop box, rotation, and displayed size. | | renderPages | Rasterize all or selected pages. | | pageSurface | Render a page-sized layer with application supplied content and attributes. | | overlayPosition | Place a PDF user-space rectangle on that layer with CSS percentages. | | Geometry functions | Convert between PDF user space and displayed page points. |

The PDF.js document APIs and pageSurface are intended for browser use. Geometry functions are pure.

import { Effect } from "effect";
import { overlayPosition, pageSurface, renderPages } from "@foldworks/pdf";

const firstPage = Effect.gen(function* () {
  const [page] = yield* renderPages(bytes, { scale: 2, pageIndexes: [0] });
  return { page, position: overlayPosition(page, widgetRect) };
});

// Later, in a view, with `page` from the result:
pageSurface(
  {
    key: "page-0",
    pageIndex: page.pageIndex,
    width: page.width,
    height: page.height,
    displayWidth: 612,
    label: "Page 1",
    content: [imageView, overlayView],
  },
  h,
);

PdfRect is a shape only; the calling API defines its coordinate space. For overlayPosition, widgetRect is in PDF user space (bottom-left origin), as stored in a widget /Rect. pageSurface uses displayed page dimensions after crop and rotation. userSpaceToDisplayRect and displayRectToUserSpace convert between that user space and top-left displayed page points. They account for offset crop boxes and quarter-turn rotations.

Effects and errors

Every document API is an Effect that fails with a typed PdfRenderError ({ reason, cause }). There are no Promise variants, so the APIs compose directly inside Foldkit Commands.

  • readPdfPages(bytes) and renderPages(bytes, options) open the document once, then read or rasterize pages in order.
  • withPdfDocument(bytes, use) opens a document for your own Effect. It uses Effect.acquireUseRelease, so the PDF.js worker is released even when use fails or is interrupted.
  • getPage(document, pageIndex) loads a zero-based page and fails with a PdfRenderError for an index that does not exist.
  • rasterizePage(page, scale, imageType) draws one page and returns a data: URL with its pixel size.

Limitations

  • /UserUnit is not applied to page sizes. Page width, height, and cropBox are read from the page's view box in user-space units, as if each unit were one point. PDF.js does apply /UserUnit when it rasterizes, so for a page with /UserUnit other than 1:

    • overlays and overlayPosition still line up, because they are placed as fractions of the page;
    • "100%" in a viewer shows the page at its unit count, not its physical size;
    • renderPages produces scale × UserUnit pixels per unit, so large /UserUnit values can create very large canvases. Check pixelWidth or lower scale if that matters.

    /UserUnit is rare outside large-format drawings.

The ready-made @foldworks/pdf-viewer and @foldworks/pdf-annotator compose these primitives.