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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@cqsjjb/jjb-html-to-pdf

v0.0.1-alpha.3

Published

HTML to PDF

Downloads

13

Readme

@cqsjjb/jjb-html-to-pdf

一个简单易用的HTML转PDF工具库,基于html2canvas和jsPDF实现。

特性

  • 🚀 支持HTML字符串或DOM元素转PDF
  • 📄 支持多页PDF生成
  • 🎨 可自定义PDF格式、尺寸、边距等
  • 🔧 支持html2canvas的所有配置选项
  • 📱 支持高清晰度输出
  • 💻 TypeScript支持

安装

npm install @cqsjjb/jjb-html-to-pdf

使用方法

基础用法

import htmlToPDF from '@cqsjjb/jjb-html-to-pdf';

// 使用HTML字符串
const htmlString = '<div><h1>Hello World</h1><p>这是一个测试文档</p></div>';
await htmlToPDF(htmlString, {
  fileName: 'test.pdf'
});

// 使用DOM元素
const element = document.getElementById('my-content');
await htmlToPDF(element, {
  fileName: 'content.pdf'
});

高级配置

import htmlToPDF from '@cqsjjb/jjb-html-to-pdf';

await htmlToPDF(htmlString, {
  fileName: 'custom.pdf',
  leftMargin: 15,
  topMargin: 20,
  pdf: {
    format: 'a4',
    unit: 'mm',
    size: 'a4'
  },
  canvas: {
    scale: 3,
    useCORS: true,
    options: {
      backgroundColor: '#ffffff',
      logging: false
    }
  }
});

API 参考

htmlToPDF(html, options?)

参数

  • html: string | HTMLElement - HTML字符串或DOM元素
  • options?: HtmlToPDFOptions - 配置选项

HtmlToPDFOptions

| 属性 | 类型 | 默认值 | 描述 | |------|------|--------|------| | fileName | string | "output.pdf" | 导出的PDF文件名 | | leftMargin | number | 10 | 左边距(mm) | | topMargin | number | 10 | 上边距(mm) | | pdf | object | {} | PDF相关配置 | | pdf.format | 'p' \| 'l' | 'p' | PDF格式(纵向/横向) | | pdf.unit | 'mm' \| 'pt' \| 'in' \| 'cm' | 'mm' | PDF单位 | | pdf.size | string | 'a4' | PDF尺寸 | | canvas | object | {} | html2canvas配置 | | canvas.scale | number | 2 | 清晰度缩放比例 | | canvas.useCORS | boolean | true | 是否使用CORS | | canvas.options | Record<string, any> | {} | html2canvas的额外选项 |

依赖

许可证

MIT

作者

jjb-front-team