跳转到主要内容

PDF Tools API

发票生成 API

在后端、批处理或产品流程中生成发票 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/invoice-generator/pdf

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

Use case

适合把账单系统、后台管理或自动化流程中的发票 JSON 转成 PDF。网页工具用于人工处理,API 用于稳定的服务端自动化。

cURL example

curl -X POST https://itextmaster.com/api/external/invoice-generator/pdf \
  -H 'x-api-key: YOUR_API_KEY' \
  -F 'invoiceNumber=INV-001' \
  -F 'fromName=Your Company' \
  -F 'billToName=Client Name' \
  -F 'items=[{"description":"Consulting","quantity":10,"rate":150}]' \
  --output invoice.pdf

Multipart example

curl -X POST https://itextmaster.com/api/external/invoice-generator/pdf \
  -H 'x-api-key: YOUR_API_KEY' \
  -F 'invoiceNumber=INV-001' \
  -F 'fromName=Your Company' \
  -F 'billToName=Client Name' \
  -F 'items=[{"description":"Consulting","quantity":10,"rate":150}]' \
  --output invoice.pdf

JSON base64 example

curl -X POST https://itextmaster.com/api/external/invoice-generator/pdf \
  -H 'Content-Type: application/json' \
  -H 'x-api-key: YOUR_API_KEY' \
  -d '{
    "invoiceNumber": "INV-001",
    "from": { "name": "Your Company", "email": "you@example.com" },
    "billTo": { "name": "Client Name", "email": "client@example.com" },
    "items": [{ "description": "Consulting", "quantity": 10, "rate": 150 }]
  }' \
  --output invoice.pdf

Node.js example

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

const response = await fetch('https://itextmaster.com/api/external/invoice-generator/pdf', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'x-api-key': process.env.ITEXTMASTER_API_KEY
  },
  body: JSON.stringify({
  invoiceNumber: 'INV-001',
  from: { name: 'Your Company', email: 'you@example.com' },
  billTo: { name: 'Client Name', email: 'client@example.com' },
  items: [{ description: 'Consulting', quantity: 10, rate: 150 }]
})
});

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

await writeFile('invoice.pdf', Buffer.from(await response.arrayBuffer()));

Python example

import os
import requests

response = requests.post(
    'https://itextmaster.com/api/external/invoice-generator/pdf',
    headers={
        'Content-Type': 'application/json',
        'x-api-key': os.environ['ITEXTMASTER_API_KEY'],
    },
    json={
        'invoiceNumber': 'INV-001',
        'from': {'name': 'Your Company', 'email': 'you@example.com'},
        'billTo': {'name': 'Client Name', 'email': 'client@example.com'},
        'items': [{'description': 'Consulting', 'quantity': 10, 'rate': 150}],
    },
)
response.raise_for_status()

with open('invoice.pdf', 'wb') as f:
    f.write(response.content)

Error codes

400invalid_invoice_payload

发票 JSON 格式错误或缺少必填字段。

401invalid_api_key

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

402insufficient_credits

账号 API Credits 不足。

500invoice_pdf_generation_failed

发票 PDF 渲染失败;失败处理会自动退回 Credits。

Limits

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

Response headers

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

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

FAQ

发票生成 API 怎么计费?

成功的 发票生成 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 发票生成 API, and buy more Credits only when automation volume grows.