← 返回
未分类 中文

HTML to PDF

Convert HTML files and URLs to PDF using Puppeteer. Use when a user needs to convert HTML documents, web pages, or reports to PDF format with custom formatti...
使用 Puppeteer 将 HTML 文件和 URL转换为 PDF,适用于将 HTML 文档、网页或报表转为自定义格式的 PDF 场景。
hankagent hankagent 来源
未分类 clawhub v1.0.0 1 版本 99928.3 Key: 无需
★ 0
Stars
📥 1,393
下载
💾 3
安装
1
版本
#latest

概述

HTML to PDF Conversion

Convert HTML files and web pages to professional PDF documents using Puppeteer.

Quick Start

CLI Usage

node scripts/html-to-pdf.js input.html output.pdf
node scripts/html-to-pdf.js input.html output.pdf A4
node scripts/html-to-pdf.js https://example.com output.pdf A4

Programmatic Usage

const convertHtmlToPdf = require('./scripts/html-to-pdf.js');

// Simple conversion
await convertHtmlToPdf('input.html', 'output.pdf');

// With options
await convertHtmlToPdf('input.html', 'output.pdf', {
  format: 'Letter',
  landscape: true,
  margin: { top: '20mm', bottom: '20mm' }
});

Features

  • ✅ Convert local HTML files
  • ✅ Convert web URLs (http/https)
  • ✅ Customizable page formats (A4, Letter, etc.)
  • ✅ Custom margins and spacing
  • ✅ Landscape/portrait modes
  • ✅ Print backgrounds
  • ✅ Headers and footers
  • ✅ Page ranges
  • ✅ Zoom scaling

Common Options

OptionTypeDefaultNotes
------------------------------
formatstring'A4'A4, Letter, A3, A5, etc.
landscapebooleanfalseLandscape orientation
marginobject10mm all{ top, right, bottom, left }
scalenumber10.1 to 2.0
printBackgroundbooleantrueInclude background colors
displayHeaderFooterbooleanfalseShow header/footer

Advanced Usage

With Headers and Footers

await convertHtmlToPdf('page.html', 'output.pdf', {
  displayHeaderFooter: true,
  headerTemplate: '<div>Page <span class="pageNumber"></span></div>',
  footerTemplate: '<div>© 2024</div>',
  margin: { top: '40px', bottom: '40px' }
});

Specific Page Ranges

await convertHtmlToPdf('document.html', 'pages-1-5.pdf', {
  pageRanges: '1-5'
});

Installation

Requires Node.js and npm:

npm install puppeteer

Reference

For complete API documentation and all available options, see api.md.

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-05-01 04:28 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

office-efficiency

Nano Pdf

steipete
使用nano-pdf CLI通过自然语言指令编辑PDF
★ 277 📥 116,352
office-efficiency

Excel / XLSX

ivangdavila
创建、检查和编辑 Microsoft Excel 工作簿及 XLSX 文件,支持可靠的公式、日期、类型、格式、重算及模板保留功能。
★ 383 📥 145,730
office-efficiency

Word / DOCX

ivangdavila
创建、检查和编辑 Microsoft Word 文档及 DOCX 文件,支持样式、编号、修订记录、表格、分节符及兼容性检查等功能。
★ 460 📥 153,296