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

@amplo/print-host

v0.1.0

Published

Angular directive-based printing utility (iframe, pagination, font/image stabilization)

Readme

print-host

A lightweight, framework-friendly Angular utility for reliable, paginated printing using an isolated iframe.

print-host solves common browser printing problems:

  • Phantom blank pages
  • Inconsistent pagination
  • Missing styles, fonts, or images
  • Print CSS bleeding into the main app
  • Unreliable window.print() behavior

It works by cloning a DOM subtree into a hidden iframe, injecting styles deterministically, paginating content in pixels (not guesses), and printing cleanly.


Features

  • ✅ Iframe-isolated printing (no app CSS pollution)
  • ✅ Deterministic pagination for A4
  • ✅ Page-break control via CSS selectors
  • ✅ Multiple style injection strategies
  • ✅ Font & image readiness before printing
  • ✅ Standalone Angular directive
  • ✅ Safe DOM cloning (no innerHTML)

Installation

npm install @amplo/print-host

Basic Usage

<div printHost #ph="printHost">
  <div class="print-content">
    <!-- printable content -->
  </div>
</div>

<button (click)="ph.print()">Print</button>

Defaults

  • First child of the host is printed
  • A4 paper size
  • 10mm margins
  • Pagination enabled
  • Host styles copied into the iframe

Directive Inputs

Core Options

| Input | Default | Description | | --------------------- | --------------- | ------------------------------------ | | printRoot | — | HTMLElement or ElementRef to print | | printSelector | — | Selector inside host to print | | pageMarginMm | 10 | A4 page margin in millimeters | | paginate | true | Enable cursor-based pagination | | extraCss | '' | Additional print-only CSS | | breakBeforeSelector | .break-before | Selector forcing page breaks |


Style Injection

Control how styles are injected into the iframe.

Built-in Modes

<div printHost styleInjectorKey="copy"></div>
<div printHost styleInjectorKey="links"></div>
<div printHost styleInjectorKey="none"></div>

| Mode | Description | | ------- | ------------------------------------- | | copy | Copy <link> and <style> from host | | links | Copy only stylesheet links | | none | No styles injected |


Custom Style Injectors

Register custom injectors globally:

import { providePrintHost } from "print-host";
import { InlineCssInjector } from "print-host/style";

bootstrapApplication(AppComponent, {
  providers: [
    providePrintHost({
      styleInjectors: [
        new InlineCssInjector("print", {
          href: "assets/print.css",
          cache: true,
        }),
      ],
    }),
  ],
});

Select the injector by key:

<div printHost styleInjectorKey="print"></div>

Page Breaks

Force a Page Break Before an Element

<div class="break-before"></div>

Custom Break Selector

<div printHost breakBeforeSelector=".force-break"></div>

Events

<div printHost (printStarted)="onPrintStart()" (printFinished)="onPrintEnd()"></div>

Typical use cases:

  • Showing / hiding loaders
  • Locking UI during print
  • Logging print lifecycle events

How Pagination Works

  • Measures real element heights using getBoundingClientRect
  • Converts A4 height using measured px/mm
  • Inserts page breaks only when required
  • Avoids tiny dangling content at page bottoms
  • Removes consecutive and trailing breaks automatically

This avoids browser heuristics and provides consistent results across Chrome and Edge.


Safety & Stability

print-host intentionally avoids:

  • innerHTML
  • Arbitrary HTML injection
  • Mutating the original DOM

All content is cloned, sanitized, and printed in isolation inside an iframe.


When to Use

  • Reports
  • Invoices
  • Dashboards
  • Admin exports
  • Any layout where print fidelity matters

When Not to Use

  • Simple one-page text printing
  • Cases where browser default printing is sufficient

License

MIT