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

@gaumala/http-pdf-printer

v0.1.0

Published

HTTP server for generating PDFs from HTML using Puppeteer

Downloads

3

Readme

HTTP PDF Printer

A Node.js library that provides an HTTP server for generating PDFs from HTML. It uses Puppeteer to render HTML documents and serves them as PDFs via a REST API.

Features

  • Generate PDFs from HTML via HTTP API
  • Configurable HTML generation function
  • Static file serving for CSS, images, fonts, etc.
  • Scheduled automatic browser restarts (configurable via cron schedule)
  • Health check endpoint
  • Document-based architecture for efficient PDF generation

Installation

npm install @gaumala/http-pdf-printer

Quick Start

Running the Sample

The project includes a sample application that demonstrates basic usage. First, clone the repository:

git clone <repository-url>
cd http-pdf-printer
npm install

Then run the sample:

node sample/app.js

The sample will start the server and use sample/static/ as the static directory for CSS and other assets.

This will start the server on http://localhost:12480 with the doc server on http://localhost:12481.

Generating a PDF with curl

Once the server is running, you can generate a PDF by sending a PUT request to the /print endpoint:

curl -X PUT http://localhost:12480/print \
  -H "Content-Type: application/json" \
  -d '{"name": "John"}' \
  --output output.pdf

The server will:

  1. Generate HTML from your JSON data using the generateHTML function
  2. Register the HTML document in the doc server
  3. Use Puppeteer to render the HTML and generate a PDF
  4. Return the PDF as the response
  5. Clean up the HTML document

API Endpoints

PUT /print

Generates a PDF from JSON data.

Request:

  • Method: PUT
  • Content-Type: application/json
  • Body: JSON object (structure depends on your generateHTML function)

Response:

  • Content-Type: application/pdf
  • Body: PDF file

PUT /restart

Manually restarts the Puppeteer browser instance.

Request:

  • Method: PUT

Response:

  • Status: 200 OK

GET /health

Health check endpoint.

Request:

  • Method: GET

Response:

  • Status: 200 OK (healthy) or 503 Service Unavailable (unhealthy)
  • Content-Type: application/json
  • Body: {"status": "healthy", "timestamp": "..."} or {"status": "unhealthy", "error": "...", "timestamp": "..."}

Usage as a Library

import { runServer } from "@gaumala/http-pdf-printer";

const generateHTML = async (data) => {
  // Your HTML generation logic here
  return `<html>...</html>`;
};

const stop = await runServer({
  generateHTML,
  staticDir: "/path/to/static/files",
  port: 12480, // optional, defaults to 12480
  host: "localhost", // optional, defaults to "localhost"
  restartSchedule: "0 0 * * *", // optional, defaults to daily at midnight
});

// Later, to stop the server:
stop();

Options

  • generateHTML (required): Async function that takes JSON data and returns HTML string
  • staticDir (required): Absolute path to directory containing static files (CSS, images, fonts, etc.)
  • port (optional): Port number for the main server (default: 12480)
  • host (optional): Hostname for the server (default: "localhost")
  • restartSchedule (optional): Cron schedule for automatic browser restarts (default: "0 0 * * *" - daily at midnight)

Project Structure

http-pdf-printer/
├── src/
│   ├── index.js          # Main library entry point
│   ├── doc-server.js     # Document server for HTML storage
│   ├── http.js           # HTTP utilities
│   └── pdf-printer.js    # Puppeteer PDF generation
├── sample/
│   ├── app.js            # Sample application
│   └── static/
│       └── style.css     # Sample CSS file
└── package.json

License

MIT