Elysia Tools Docs
ZH
语言
ZHESPTRUFRDEEN
返回主站
浏览工具

Document Tools

HTML转PDF(精确排版)

使用浏览器渲染HTML/CSS生成精确页眉页脚的PDF

file· 文件结果打开工具

快速开始

用三种语言从你的代码中调用此工具。

cURL
curl -X POST 'https://api.elysiatools.com/zh/api/tools/html-to-pdf-precise' \
  -H 'Content-Type: application/json' \
  -d '{"htmlContent":"<h1>Hello PDF</h1><p>Write your HTML here...</p>","cssContent":"/* Optional custom styles */","pageSize":"A4","landscape":false,"printBackground":true,"scale":1,"marginTop":20,"marginBottom":20,"marginLeft":20,"marginRight":20,"headerTemplate":"<div style=\"font-size:10px; width:100%; text-align:center;\"><span class=\"pageNumber\"></span>1/20<span class=\"totalPages\"></span></div>","footerTemplate":"<div style=\"font-size:10px; width:100%; text-align:center;\">Confidential</div>","mediaType":"print","waitUntil":"networkidle0","waitTime":3000,"preferCssPageSize":false}'

© 2026 Elysia Tools. 开发者文档。

返回主站浏览工具

API 参考

以 JSON 形式 POST 提交输入参数。文件类型参数需先单独上传。

请求端点

HTTP
POST https://api.elysiatools.com/zh/api/tools/html-to-pdf-precise

请求参数

参数名类型必填说明
htmlContenttextarea是—
cssContenttextarea否—
pageSizeselect否—
landscapecheckbox否—
printBackgroundcheckbox否—
scalenumber否—
marginTopnumber否—
marginBottomnumber否—
marginLeftnumber否—
marginRightnumber否—
headerTemplatetextarea否—
footerTemplatetextarea否—
mediaTypeselect否—
waitUntilselect否—
waitTimenumber否—
preferCssPageSizecheckbox否—

响应格式

文件结果

JSON
{
  "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)"
}

MCP 集成

将此工具加入你的 Model Context Protocol 服务,让 AI 智能体可以列出并调用它。

服务配置

将以下内容加入你的 MCP 客户端配置:

mcp.json
{
  "mcpServers": {
    "elysiatools-html-to-pdf-precise": {
      "name": "html-to-pdf-precise",
      "description": "使用浏览器渲染HTML/CSS生成精确页眉页脚的PDF",
      "baseUrl": "https://api.elysiatools.com/mcp/sse?toolId=html-to-pdf-precise",
      "command": "",
      "args": [],
      "env": {},
      "isActive": true,
      "type": "sse"
    }
  }
}

列出可用工具

连接到 SSE 端点后,列出已开放的工具:

tools/list
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/list"
}

调用此工具

通过工具 id 调用,参数由其参数表构建:

tools/call
{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "tools/call",
  "params": {
    "name": "html-to-pdf-precise",
    "arguments": {
  "htmlContent": "<h1>Hello PDF</h1><p>Write your HTML here...</p>",
  "cssContent": "/* Optional custom styles */",
  "pageSize": "A4",
  "landscape": false,
  "printBackground": true,
  "scale": 1,
  "marginTop": 20,
  "marginBottom": 20,
  "marginLeft": 20,
  "marginRight": 20,
  "headerTemplate": "<div style=\"font-size:10px; width:100%; text-align:center;\"><span class=\"pageNumber\"></span>1/20<span class=\"totalPages\"></span></div>",
  "footerTemplate": "<div style=\"font-size:10px; width:100%; text-align:center;\">Confidential</div>",
  "mediaType": "print",
  "waitUntil": "networkidle0",
  "waitTime": 3000,
  "preferCssPageSize": false
}
  }
}
可用逗号分隔的 toolId 在一个会话中串联多个工具,例如 /mcp/sse?toolId=png-to-webp,jpg-to-webp,gif-to-webp(最多 20 个)。

有问题或反馈?请联系 [email protected]

浏览工具
打开工具