
anishathalye/proof-htmlproof-html是一个基于Headless Chrome的HTML转PDF工具,能够准确渲染现代HTML/CSS并生成高质量PDF文档。该工具特别适合需要从网页或HTML模板生成精确定制PDF的场景,提供了丰富的自定义选项以满足各种文档需求。
最简单的使用方式是将当前目录的HTML文件转换为PDF:
bashdocker run --rm -v $(pwd):/workspace anishathalye/proof-html input.html output.pdf
指定页面大小、方向和边距:
bashdocker run --rm -v $(pwd):/workspace anishathalye/proof-html \ --page-size A4 \ --orientation portrait \ --margin-top 2cm \ --margin-right 2cm \ --margin-bottom 2cm \ --margin-left 2cm \ input.html output.pdf
bashdocker run --rm -v $(pwd):/workspace anishathalye/proof-html \ --header "报告标题" \ --footer "第 [page] 页,共 [total] 页" \ input.html output.pdf
bashdocker run --rm -v $(pwd):/workspace anishathalye/proof-html \ --title "年度财务报告" \ --author "财务部门" \ --subject "2023年度财务总结" \ --keywords "财务,报告,2023,年度总结" \ report.html report.pdf
创建docker-compose.yml文件:
yamlversion: '3' services: pdf-generator: image: anishathalye/proof-html volumes: - ./html:/workspace/html - ./pdf:/workspace/pdf command: ["--page-size", "Letter", "--margin-top", "1in", "html/report.html", "pdf/report.pdf"]
运行服务:
bashdocker-compose run --rm pdf-generator
| 参数 | 描述 | 默认值 |
|---|---|---|
--page-size | 设置页面大小 (A4, Letter, Legal, Tabloid等) | A4 |
--orientation | 设置页面方向 (portrait/landscape) | portrait |
--margin-top | 页面顶部边距 (单位: cm, mm, in) | 0 |
--margin-right | 页面右侧边距 (单位: cm, mm, in) | 0 |
--margin-bottom | 页面底部边距 (单位: cm, mm, in) | 0 |
--margin-left | 页面左侧边距 (单位: cm, mm, in) | 0 |
--header | 页眉文本,支持 [page] 和 [total] 变量 | 无 |
--footer | 页脚文本,支持 [page] 和 [total] 变量 | 无 |
--title | PDF文档标题元数据 | 无 |
--author | PDF文档作者元数据 | 无 |
--subject | PDF文档主题元数据 | 无 |
--keywords | PDF文档关键字元数据 | 无 |
--delay | 等待JavaScript执行的延迟时间(毫秒) | 0 |
--bookmarks | 从HTML标题(h1-h6)生成PDF书签 | false |
--quiet | 静默模式,不输出处理日志 | false |
直接从网页URL生成PDF:
bashdocker run --rm -v $(pwd):/workspace anishathalye/proof-html \ [***] documentation.pdf
对于包含大量JavaScript或异步加载内容的页面,使用延迟参数确保内容完全加载:
bashdocker run --rm -v $(pwd):/workspace anishathalye/proof-html \ --delay 5000 \ --page-size Letter \ dynamic-content.html report.pdf
从HTML标题自动生成PDF书签:
bashdocker run --rm -v $(pwd):/workspace anishathalye/proof-html \ --bookmarks \ --title "产品手册" \ --author "技术文档团队" \ manual.html product-manual.pdf
@font-face定义print媒体查询可以为PDF输出定义特定样式css/* 示例:PDF专用样式 */ @media print { .no-print { display: none !important; } body { font-size: 12pt; line-height: 1.5; } }





manifest unknown 错误
TLS 证书验证失败
DNS 解析超时
410 错误:版本过低
402 错误:流量耗尽
身份认证失败错误
429 限流错误
凭证保存错误
来自真实用户的反馈,见证轩辕镜像的优质服务