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

@a4-pagination-print/renderer-browser

v0.1.1

Published

A4 browser renderer — DOM, print, single-page PDF

Downloads

233

Readme

@a4-pagination-print/renderer-browser

npm version license

A4 浏览器端渲染器 — DOM 渲染、浏览器打印、单页 PDF 生成。

npm install @a4-pagination-print/renderer-browser @a4-pagination-print/core

适用场景

  • 在浏览器中把 Page 数据渲染为 DOM
  • 调用浏览器原生 window.print() 打印 A4 页面
  • 使用 html2canvas + jspdf 生成单页 PDF(不依赖服务端)

功能

Renderer — DOM 渲染

import { Renderer } from '@a4-pagination-print/renderer-browser';

const renderer = new Renderer({
  element: document.getElementById('app'),
  scale: 3.78,      // mm → px
});

// 渲染单页
renderer.render(page);

// 渲染多页
renderer.renderAll(pages);

// 清理
renderer.destroy();

PageNavigator — 浏览器端翻页

import { BrowserPageNavigator } from '@a4-pagination-print/renderer-browser';

const nav = new BrowserPageNavigator({
  pages,
  element: document.getElementById('app'),
  onPageChange: (index) => console.log(`当前第 ${index} 页`),
});

nav.next();
nav.prev();
nav.goTo(5);

print — 浏览器打印

import { printPage, printAllPages } from '@a4-pagination-print/renderer-browser';

// 打印单页
printPage(page);

// 打印全部
printAllPages(pages);

Single PDF — 浏览器端 PDF

import { generateSinglePdf } from '@a4-pagination-print/renderer-browser';

// 生成单页 PDF(需要 html2canvas 和 jspdf)
const pdf = await generateSinglePdf(page, {
  filename: 'report.pdf',
  scale: 2,     // 提高清晰度
});

可选依赖

以下依赖为 peerDependencies,按需安装:

| 包 | 用途 | 是否必需 | |---|---|---| | html2canvas | 将 DOM 转为 Canvas | PDF 生成时需要 | | jspdf | 生成 PDF 文件 | PDF 生成时需要 |

# 如需 PDF 生成功能
npm install html2canvas jspdf

依赖

  • @a4-pagination-print/core — 分页引擎

License

MIT