跳转到主要内容

PDF Tools API

HTML 转 PDF API

在后端、批处理或产品流程中把 HTML 转成 PDF,不必自己维护 PDF 处理基础设施;成功请求按 Credits 计费。

Credits

1 Credit / call

1 Credit per successful API request. Failed processing attempts are refunded automatically.

Pricing

1,000 Credits = $1

Every signed-in user receives 100 free API Credits each month.

Endpoint

/api/external/html-to-pdf/pdf

Use your API Key in the x-api-key header.

Use case

适合在服务端把报表、收据、对账单或内部页面渲染为可归档 PDF。网页工具用于人工处理,API 用于稳定的服务端自动化。

cURL example

curl -X POST https://itextmaster.com/api/external/html-to-pdf/pdf \
  -H 'x-api-key: YOUR_API_KEY' \
  -F 'html=@index.html;type=text/html' \
  -F 'pageSize=A4' \
  -F 'printBackground=true' \
  --output html-to-pdf.pdf

Multipart example

curl -X POST https://itextmaster.com/api/external/html-to-pdf/pdf \
  -H 'x-api-key: YOUR_API_KEY' \
  -F 'html=@index.html;type=text/html' \
  -F 'pageSize=A4' \
  -F 'printBackground=true' \
  --output html-to-pdf.pdf

JSON base64 example

curl -X POST https://itextmaster.com/api/external/html-to-pdf/pdf \
  -H 'Content-Type: application/json' \
  -H 'x-api-key: YOUR_API_KEY' \
  -d '{
    "html": "<!doctype html><html><body><h1>Report</h1></body></html>",
    "pageSize": "A4",
    "printBackground": true
  }' \
  --output html-to-pdf.pdf

Node.js example

import { writeFile } from 'node:fs/promises';

const response = await fetch('https://itextmaster.com/api/external/html-to-pdf/pdf', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'x-api-key': process.env.ITEXTMASTER_API_KEY
  },
  body: JSON.stringify({
  html: '<!doctype html><html><body><h1>Report</h1></body></html>',
  pageSize: 'A4',
  printBackground: true
})
});

if (!response.ok) {
  throw new Error(await response.text());
}

await writeFile('html-to-pdf.pdf', Buffer.from(await response.arrayBuffer()));

Python example

import os
import requests

response = requests.post(
    'https://itextmaster.com/api/external/html-to-pdf/pdf',
    headers={
        'Content-Type': 'application/json',
        'x-api-key': os.environ['ITEXTMASTER_API_KEY'],
    },
    json={
        'html': '<!doctype html><html><body><h1>Report</h1></body></html>',
        'pageSize': 'A4',
        'printBackground': True,
    },
)
response.raise_for_status()

with open('html-to-pdf.pdf', 'wb') as f:
    f.write(response.content)

Error codes

400invalid_payload

JSON 或 multipart 请求缺少必填的 HTML、URL 或文件输入。

401invalid_api_key

x-api-key 缺失、无效或已经轮换。

402insufficient_credits

账号 API Credits 不足。

502conversion_failed

服务端渲染没有完成转换;失败处理会自动退回 Credits。

Limits

  • 需要可正常打开的 PDF 或有效输入数据。
  • 请从服务端调用 API,不要在浏览器暴露 API Key。
  • 复杂文件建议先用代表性样本测试输出质量。

Response headers

html-to-pdf.pdf,响应头会返回本次消耗的 Credits 和剩余额度。

Content-Type
生成文件的 MIME 类型,通常是 application/pdf 或 application/zip。
Content-Disposition
生成文件的下载文件名。
X-Credits-Charged
成功请求实际扣除的 Credits。
X-Credit-Balance
请求完成后的剩余 API Credits。

FAQ

HTML 转 PDF API 怎么计费?

成功的 HTML 转 PDF API 请求会消耗 API Credits;失败处理会自动退回。每个登录用户每月有 100 个免费 API Credits,1,000 Credits = $1。

网站工具会消耗 API Credits 吗?

浏览器本地处理的网站工具不消耗 API Credits;只有通过 API Key 发起的自动化请求才按 Credits 计费。

可以从前端直接调用吗?

不建议。API Key 应保存在服务端、队列任务或自动化脚本中。

Start with 100 free API Credits

Create an API Key, test HTML 转 PDF API, and buy more Credits only when automation volume grows.

iTextMaster

专业PDF工具 - 免费且私密

安全

  • 本地优先处理大多数文件工具在浏览器中运行。
  • 服务端处理清晰提示需要服务端处理的工具会在提交前明确说明。

选择语言

© 2026 iTextMaster. © iTextMaster. 保留所有权利。