HTML转PDF(精确排版)
使用浏览器渲染HTML/CSS生成精确页眉页脚的PDF
此工具使用无头浏览器渲染HTML/CSS,适合高精度排版。
**页眉页脚:**
- 支持自定义HTML模板
- 使用 `<span class="pageNumber"></span>` 与 `<span class="totalPages"></span>` 显示页码
- 可直接写内联样式
**打印设置:**
- A4/Letter/Legal页面大小
- 边距(毫米)
- 背景打印与缩放
- 支持 `@page` 与 `@media print`(启用“优先CSS页面尺寸”)
API 文档
请求端点
POST /zh/api/tools/html-to-pdf-precise
请求参数
| 参数名 | 类型 | 必填 | 描述 |
|---|---|---|---|
| htmlContent | textarea | 是 | - |
| cssContent | textarea | 否 | - |
| pageSize | select | 否 | - |
| landscape | checkbox | 否 | - |
| printBackground | checkbox | 否 | - |
| scale | number | 否 | - |
| marginTop | number | 否 | - |
| marginBottom | number | 否 | - |
| marginLeft | number | 否 | - |
| marginRight | number | 否 | - |
| headerTemplate | textarea | 否 | - |
| footerTemplate | textarea | 否 | - |
| mediaType | select | 否 | - |
| waitUntil | select | 否 | - |
| waitTime | number | 否 | - |
| preferCssPageSize | checkbox | 否 | - |
响应格式
{
"filePath": "/public/processing/randomid.ext",
"fileName": "output.ext",
"contentType": "application/octet-stream",
"size": 1024,
"metadata": {
"key": "value"
},
"error": "Error message (optional)",
"message": "Notification message (optional)"
}
文件:
文件
AI MCP 文档
将此工具添加到您的 MCP 服务器配置中:
{
"mcpServers": {
"elysiatools-html-to-pdf-precise": {
"name": "html-to-pdf-precise",
"description": "使用浏览器渲染HTML/CSS生成精确页眉页脚的PDF",
"baseUrl": "https://elysiatools.com/mcp/sse?toolId=html-to-pdf-precise",
"command": "",
"args": [],
"env": {},
"isActive": true,
"type": "sse"
}
}
}
你可以串联多个工具,比如:`https://elysiatools.com/mcp/sse?toolId=png-to-webp,jpg-to-webp,gif-to-webp`,最多20个。
如果遇见问题,请联系我们:[email protected]