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

electron-print-document

v0.1.1

Published

Printing library for Electron.

Readme

electron-print-document

Printing library for Electron.

Install

npm install electron-print-document

Basic Usage

import { printDocument } from "electron-print-document";

await printDocument({
  document: {
    title: "Receipt",
    html: `
      <section style="padding: 8mm; font-family: sans-serif;">
        <h1 style="margin: 0 0 4mm;">My Store</h1>
        <p style="margin: 0 0 2mm;">Order #1024</p>
        <p style="margin: 0;">Thank you.</p>
      </section>
    `,
  },
  page: {
    size: "receipt-80mm",
    margins: 0,
  },
  print: {
    silent: true,
    printerName: "XP-80C",
    copies: 1,
  },
});

Option Layout

  • document: HTML, title, styles, and document metadata.
  • page: paper size, margins, and orientation.
  • print: printer behavior such as silent, printerName, and copies.
  • window / loadUrl: Electron window and loading options for advanced cases.

SSR Usage

import React from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { printDocument } from "electron-print-document";

function Receipt({ order }) {
  return (
    <section className="receipt">
      <h1>Northwind Coffee</h1>
      <p>Order {order.number}</p>
      <p>{order.paidAt}</p>

      <div className="receipt-items">
        {order.items.map((item) => (
          <div key={item.name} className="receipt-item">
            <span>{item.name}</span>
            <strong>{item.total}</strong>
          </div>
        ))}
      </div>

      <div className="receipt-total">
        <span>Total</span>
        <strong>{order.total}</strong>
      </div>
    </section>
  );
}

await printDocument({
  document: {
    title: order.number,
    styles: `
      body {
        font-family: "SF Pro Text", "Segoe UI", sans-serif;
        color: #111827;
      }

      .receipt {
        padding: 5mm 4.5mm 6mm;
        font-size: 12px;
        line-height: 1.35;
        background: #fff;
      }

      .receipt-items {
        margin: 4mm 0;
      }

      .receipt-item,
      .receipt-total {
        display: flex;
        justify-content: space-between;
      }
    `,
    html: () => renderToStaticMarkup(<Receipt order={order} />),
  },
  page: {
    size: "receipt-80mm",
    margins: 0,
  },
});

Page Size

Built-in page sizes:

  • A0
  • A1
  • A2
  • A3
  • A4
  • A5
  • A6
  • Legal
  • Letter
  • Tabloid
  • receipt-44mm
  • receipt-57mm
  • receipt-58mm
  • receipt-76mm
  • receipt-78mm
  • receipt-80mm

Label sizes:

  • label-40x30mm
  • label-50x30mm
  • label-60x40mm

Use the printer default page size:

page: {
  size: "printer-default",
}

Custom size:

page: {
  size: {
    width: 80,
    height: 200,
    unit: "mm",
  },
}

Orientation belongs to page:

page: {
  size: "A4",
  orientation: "landscape",
}

print does not accept page size, margin, or orientation options. Keep paper layout in page, and keep printer behavior in print. If height is omitted, the size is treated as a roll / long paper layout.

Content Overflow

When content exceeds the page area, the default behavior is to log a warning and continue. You can change this with the fit option:

await printDocument({
  document: { html: "<div>...</div>" },
  page: { size: "label-60x40mm" },
  fit: {
    overflow: "throw", // "warn" (default) | "throw" | "ignore"
  },
});

Use "throw" for label printing where every millimeter matters, or "ignore" to suppress the warning entirely.

Window & Print Behavior

The hidden print window is automatically closed when printing finishes.

For previewDocument, pass openDevTools to inspect the rendered document:

const { window } = await previewDocument({
  document: { html },
  page: { size: "receipt-80mm" },
  openDevTools: true,
});

Main Exports

  • printDocument
  • previewDocument
  • buildPrintDocument
  • resolvePageSize
  • PAPER_PRESETS