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

@modernpdf/core

v0.1.7

Published

Core snapshot and PDF generation logic for ModernPDF

Readme

@modernpdf/core

Core client library for ModernPDF.

[!IMPORTANT] This is a client library designed to interact with the ModernPDF API. It is not a self-contained PDF generation engine (like Puppeteer or wkhtmltopdf). It handles DOM snapshotting and API communication.

Features

  • DOM Snapshotting: Captures current DOM state, inlines all CSS, converts Canvases to images, and preserves input/textarea values.
  • API Wrapper: Simple, type-safe wrapper for the ModernPDF conversion API.
  • Lightweight: Zero dependencies, works in any modern browser.

Installation

npm install @modernpdf/core
# or
pnpm add @modernpdf/core
# or
yarn add @modernpdf/core

Usage

1. Generating a PDF from a URL

If you just want to convert a public URL to a PDF:

import { generatePdf } from '@modernpdf/core';

async function downloadPage() {
  const blob = await generatePdf(
    {
      source: { url: 'https://example.com' },
      pdf: { format: 'A4' },
    },
    { apiKey: 'YOUR_API_KEY' },
  );

  // Do something with the blob (e.g., save it or open in new tab)
  const url = URL.createObjectURL(blob);
  window.open(url);
}

2. Snapshotting the current page

This is useful for generating PDFs of dynamic web apps, dashboards, or "Save as PDF" buttons where you want to capture exactly what the user sees.

import { snapshotElement, generatePdf } from '@modernpdf/core';

async function exportToPdf() {
  // 1. Capture the HTML and styles of the current page (or a specific element)
  const html = await snapshotElement(document.getElementById('report-container'));

  // 2. Send it to ModernPDF API for conversion
  const blob = await generatePdf(
    {
      source: { html },
      pdf: {
        format: 'A4',
        margin: { top: '1cm', bottom: '1cm' },
      },
    },
    { apiKey: 'YOUR_API_KEY' },
  );

  // 3. Download the result
  const url = URL.createObjectURL(blob);
  const a = document.createElement('a');
  a.href = url;
  a.download = 'report.pdf';
  a.click();
}

API Reference

snapshotElement(rootElement?: HTMLElement): Promise<string>

Captures the current state of a DOM element (defaults to document.documentElement).

  • Inlines all external and internal CSS.
  • Converts <canvas> elements to <img> tags.
  • Inlines current values of <input>, <textarea>, and <select>.
  • Removes <script> tags to ensure a static snapshot.

generatePdf(request: GeneratePdfRequest, options: ApiOptions): Promise<Blob>

Sends a request to the ModernPDF API.

  • request.source: Either { url: string } or { html: string }.
  • request.pdf: Options like format, landscape, margin, scale, etc.
  • request.wait: Wait conditions (e.g., networkidle, selector).

License

MIT