跳到正文

PDF

生成、合并、拆分、OCR 与加水印 PDF。

1. 概览

基础路径: https://api.infrai.cc/v1/pdf
鉴权头: Authorization: Bearer $INFRAI_API_KEY
bash
# Call any /v1/pdf capability over raw HTTP — no SDK to install.
# curl:
curl https://api.infrai.cc/v1/pdf/... \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json"

2. 方法 (19)

2.1pdf.generate

POST /v1/pdf/generate

从 HTML、URL 或模板生成 PDF。

参数

名称类型必填说明
htmlstring可选要渲染的 HTML 源。
urlstring可选用于渲染或操作的源 URL。
template_idstring可选用于渲染的模板 id(替代正文)。
format"A4" | "Letter" | "Legal"可选页面尺寸。
orientation"portrait" | "landscape"可选页面方向。
default: "portrait"
idempotency_keystring可选可选去重 key;相同重试将返回同一结果。

返回

PdfResult { pdf_url, bytes, pages }
名称类型说明
pdf_idstringPDF document的唯一标识符
pattern: ^pdf_[A-Za-z0-9]{20,}$
urlstring资源或端点 URL
size_bytesinteger资源大小(字节)
≥ 0
page_countintegerpages in the document数量
≥ 1
sha256string资源内容的 SHA-256 哈希
pattern: ^[a-f0-9]{64}$
created_atstring资源创建时间(ISO 8601)
format: date-time
retention_daysinteger | nulldays to retain this resource数量
≥ 0
source"html" | "markdown" | "template" | "ocr" | "mutate" | "convert" | "compress" | "encrypt" | "redact" | "form"PDF 来源(upload、url、html)

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/pdf/generate \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{}'

2.2pdf.merge

POST /v1/pdf/merge

将多个 PDF 合并为一个。

参数

名称类型必填说明
urlsstring[]
必填
要合并的 PDF URL 列表。

返回

PdfResult
名称类型说明
pdf_idstringPDF document的唯一标识符
pattern: ^pdf_[A-Za-z0-9]{20,}$
urlstring资源或端点 URL
size_bytesinteger资源大小(字节)
≥ 0
page_countintegerpages in the document数量
≥ 1
sha256string资源内容的 SHA-256 哈希
pattern: ^[a-f0-9]{64}$
created_atstring资源创建时间(ISO 8601)
format: date-time
retention_daysinteger | nulldays to retain this resource数量
≥ 0
source"html" | "markdown" | "template" | "ocr" | "mutate" | "convert" | "compress" | "encrypt" | "redact" | "form"PDF 来源(upload、url、html)

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/pdf/merge \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"inputs": ["hello"]}'

2.3pdf.split

POST /v1/pdf/split

按页码区间拆分 PDF。

参数

名称类型必填说明
urlstring
必填
用于渲染或操作的源 URL。
rangesstring[]
必填
页码区间,例如 1-3。
≥ 1 item

返回

{ parts: PdfResult[] }
名称类型说明
pdf_idstringPDF document的唯一标识符
pattern: ^pdf_[A-Za-z0-9]{20,}$
urlstring资源或端点 URL
size_bytesinteger资源大小(字节)
≥ 0
page_countintegerpages in the document数量
≥ 1
sha256string资源内容的 SHA-256 哈希
pattern: ^[a-f0-9]{64}$
created_atstring资源创建时间(ISO 8601)
format: date-time
retention_daysinteger | nulldays to retain this resource数量
≥ 0
source"html" | "markdown" | "template" | "ocr" | "mutate" | "convert" | "compress" | "encrypt" | "redact" | "form"PDF 来源(upload、url、html)

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/pdf/split \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"pdf": "sample", "ranges": [[1]]}'

2.4pdf.ocr

POST /v1/pdf/ocr

通过 OCR 从 PDF 提取文本。

参数

名称类型必填说明
urlstring
必填
用于渲染或操作的源 URL。
languagestring可选语言提示,例如 en 或 zh。

返回

{ text, pages: Array<{ text }> }
名称类型说明
pdf_idstringPDF document的唯一标识符
pattern: ^pdf_[A-Za-z0-9]{20,}$
text_per_pagestring[]每页提取的文本内容
confidence_avgnumber | nullOCR 结果的平均置信度分数
0–1
lang_detectedstring | null检测到的文档语言
duration_msinteger操作耗时(毫秒)
≥ 0
engine"chromium" | "unstructured_io" | "aws_textract" | "google_doc_ai" | "paddle_ocr"使用的处理引擎(如 tesseract、google-vision)

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/pdf/ocr \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"pdf": "sample"}'

2.5pdf.watermark

POST /v1/pdf/watermark

为 PDF 添加文字或图片水印。

参数

名称类型必填说明
urlstring
必填
用于渲染或操作的源 URL。
textstring可选水印文字。
opacitynumber可选水印不透明度,0 到 1。
0–1default: 0.3

返回

PdfResult
名称类型说明
pdf_idstringPDF document的唯一标识符
pattern: ^pdf_[A-Za-z0-9]{20,}$
urlstring资源或端点 URL
size_bytesinteger资源大小(字节)
≥ 0
page_countintegerpages in the document数量
≥ 1
sha256string资源内容的 SHA-256 哈希
pattern: ^[a-f0-9]{64}$
created_atstring资源创建时间(ISO 8601)
format: date-time
retention_daysinteger | nulldays to retain this resource数量
≥ 0
source"html" | "markdown" | "template" | "ocr" | "mutate" | "convert" | "compress" | "encrypt" | "redact" | "form"PDF 来源(upload、url、html)

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/pdf/watermark \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"pdf": "sample"}'

2.6pdf.compress

POST /v1/pdf/compress

压缩 PDF 以减小体积,mode 复用全局 fast/balanced/quality 处理档位;幂等写入,idempotency_key 用于重试去重。

参数

名称类型必填说明
pdfstring
必填
PDF 输入:URL、base64 数据或已存储的 pdf_id。
mode"fast" | "balanced" | "quality"可选压缩力度与保真的权衡,复用全局处理档位(fast/balanced/quality)。
default: "balanced"
idempotency_keystring可选可选去重 key;相同重试将返回同一结果。

返回

PdfDocument { pdf_id, url, bytes, page_count, source }
名称类型说明
pdf_idstringPDF document的唯一标识符
pattern: ^pdf_[A-Za-z0-9]{20,}$
urlstring资源或端点 URL
size_bytesinteger资源大小(字节)
≥ 0
page_countintegerpages in the document数量
≥ 1
sha256string资源内容的 SHA-256 哈希
pattern: ^[a-f0-9]{64}$
created_atstring资源创建时间(ISO 8601)
format: date-time
retention_daysinteger | nulldays to retain this resource数量
≥ 0
source"html" | "markdown" | "template" | "ocr" | "mutate" | "convert" | "compress" | "encrypt" | "redact" | "form"PDF 来源(upload、url、html)

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/pdf/compress \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"pdf": "sample"}'

2.7pdf.convert

POST /v1/pdf/convert

将 PDF 转换为其他格式;不支持的目标返回 PDF_CONVERT_UNSUPPORTED(422);多页图片目标返回 PdfDocumentListResult;幂等写入。

参数

名称类型必填说明
pdfstring
必填
PDF 输入:URL、base64 数据或已存储的 pdf_id。
to"docx" | "xlsx" | "pptx" | "png" | "jpg" | "html"
必填
目标格式(如 docx、png、jpg 等)。
idempotency_keystring可选可选去重 key;相同重试将返回同一结果。

返回

PdfDocument (multi-page image targets return PdfDocumentListResult)
名称类型说明
pdf_idstringPDF document的唯一标识符
pattern: ^pdf_[A-Za-z0-9]{20,}$
urlstring资源或端点 URL
size_bytesinteger资源大小(字节)
≥ 0
page_countintegerpages in the document数量
≥ 1
sha256string资源内容的 SHA-256 哈希
pattern: ^[a-f0-9]{64}$
created_atstring资源创建时间(ISO 8601)
format: date-time
retention_daysinteger | nulldays to retain this resource数量
≥ 0
source"html" | "markdown" | "template" | "ocr" | "mutate" | "convert" | "compress" | "encrypt" | "redact" | "form"PDF 来源(upload、url、html)

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/pdf/convert \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"pdf": "sample", "to": "docx"}'

2.8pdf.parse

POST /v1/pdf/parse

提取 PDF 文本、大纲与元数据用于 RAG 入库;只读无副作用;加密且未提供密码时返回 PDF_PARSE_PASSWORD_REQUIRED。

参数

名称类型必填说明
pdfstring
必填
PDF 输入:URL、base64 数据或已存储的 pdf_id。
pagesnumber[]可选限定解析的页码(1 起始);省略则解析全部页面。

返回

PdfParseResult { text, pages, outline, metadata }
名称类型说明
pdf_idstringPDF document的唯一标识符
pattern: ^pdf_[A-Za-z0-9]{20,}$
text_per_pagestring[]每页提取的文本内容
outlineobject[]文档大纲/目录
outline[].titlestring-
outline[].pageinteger-
metadataobject | null附加在此资源上的任意键值元数据
languagestring | null检测到的文本语言

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/pdf/parse \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"pdf": "sample"}'

2.9pdf.extract_images

POST /v1/pdf/extract_images

提取 PDF 内嵌 XObject 图片并以 data: URI 形式返回;只读无副作用。

参数

名称类型必填说明
pdfstring
必填
PDF 输入:URL、base64 数据或已存储的 pdf_id。
pagesnumber[]可选限定提取图片的页码(1 起始);省略则提取全部页面。

返回

PdfExtractImagesResult { images: ExtractedImage[] }
名称类型说明
imagesobject[]generated or processed images列表
images[].pageinteger页码(从 1 开始)
≥ 1
images[].image_urlstring提取图片的 URL
images[].widthinteger图片宽度(像素)
≥ 1
images[].heightinteger图片高度(像素)
≥ 1
images[].mime_typestring | null资源 MIME 类型

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/pdf/extract_images \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"pdf": "sample"}'

2.10pdf.form.extract

POST /v1/pdf/form/extract

读取 AcroForm 表单字段名与取值;只读无副作用。

参数

名称类型必填说明
pdfstring
必填
PDF 输入:URL、base64 数据或已存储的 pdf_id。

返回

PdfFormExtractResult { fields }
名称类型说明
fieldsobject[]提取的表单字段
fields[].namestring-
fields[].typestringAcroForm 字段类型(text、checkbox、radio、choice、signature)。
fields[].valuestring | boolean | null-

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/pdf/form/extract \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"pdf": "sample"}'

2.11pdf.form.fill

POST /v1/pdf/form/fill

填充 AcroForm 表单字段;flatten 压平为不可编辑;幂等写入,idempotency_key 用于重试去重。

参数

名称类型必填说明
pdfstring
必填
PDF 输入:URL、base64 数据或已存储的 pdf_id。
fieldsRecord<string, string>
必填
字段名到取值的映射,用于填充表单。
flattenboolean可选为 true 时将填充值压平,使表单不可再编辑。
default: false
idempotency_keystring可选可选去重 key;相同重试将返回同一结果。

返回

PdfDocument { pdf_id, url, page_count, source }
名称类型说明
pdf_idstringPDF document的唯一标识符
pattern: ^pdf_[A-Za-z0-9]{20,}$
urlstring资源或端点 URL
size_bytesinteger资源大小(字节)
≥ 0
page_countintegerpages in the document数量
≥ 1
sha256string资源内容的 SHA-256 哈希
pattern: ^[a-f0-9]{64}$
created_atstring资源创建时间(ISO 8601)
format: date-time
retention_daysinteger | nulldays to retain this resource数量
≥ 0
source"html" | "markdown" | "template" | "ocr" | "mutate" | "convert" | "compress" | "encrypt" | "redact" | "form"PDF 来源(upload、url、html)

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/pdf/form/fill \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"pdf": "sample", "fields": {}}'

2.12pdf.encrypt

POST /v1/pdf/encrypt

为 PDF 应用密码与权限加密;幂等写入,idempotency_key 用于重试去重。

参数

名称类型必填说明
pdfstring
必填
PDF 输入:URL、base64 数据或已存储的 pdf_id。
user_passwordstring可选打开文档所需的用户密码。
owner_passwordstring可选用于权限控制的所有者密码。
permissionsstring[]可选允许的操作权限列表(如 print、copy 等)。
idempotency_keystring可选可选去重 key;相同重试将返回同一结果。

返回

PdfDocument { pdf_id, url, source }
名称类型说明
pdf_idstringPDF document的唯一标识符
pattern: ^pdf_[A-Za-z0-9]{20,}$
urlstring资源或端点 URL
size_bytesinteger资源大小(字节)
≥ 0
page_countintegerpages in the document数量
≥ 1
sha256string资源内容的 SHA-256 哈希
pattern: ^[a-f0-9]{64}$
created_atstring资源创建时间(ISO 8601)
format: date-time
retention_daysinteger | nulldays to retain this resource数量
≥ 0
source"html" | "markdown" | "template" | "ocr" | "mutate" | "convert" | "compress" | "encrypt" | "redact" | "form"PDF 来源(upload、url、html)

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/pdf/encrypt \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"pdf": "sample"}'

2.13pdf.decrypt

POST /v1/pdf/decrypt

去除 PDF 密码保护;缺密码返回 PDF_PARSE_PASSWORD_REQUIRED(401),密码错误返回 PDF_DECRYPT_FAILED(403);幂等写入。

参数

名称类型必填说明
pdfstring
必填
PDF 输入:URL、base64 数据或已存储的 pdf_id。
passwordstring
必填
用于解密文档的密码。
idempotency_keystring可选可选去重 key;相同重试将返回同一结果。

返回

PdfDocument { pdf_id, url, source }
名称类型说明
pdf_idstringPDF document的唯一标识符
pattern: ^pdf_[A-Za-z0-9]{20,}$
urlstring资源或端点 URL
size_bytesinteger资源大小(字节)
≥ 0
page_countintegerpages in the document数量
≥ 1
sha256string资源内容的 SHA-256 哈希
pattern: ^[a-f0-9]{64}$
created_atstring资源创建时间(ISO 8601)
format: date-time
retention_daysinteger | nulldays to retain this resource数量
≥ 0
source"html" | "markdown" | "template" | "ocr" | "mutate" | "convert" | "compress" | "encrypt" | "redact" | "form"PDF 来源(upload、url、html)

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/pdf/decrypt \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"pdf": "sample", "password": "sample"}'

2.14pdf.rotate

POST /v1/pdf/rotate

旋转指定页面;角度不在 {0,90,180,270} 或页码越界均返回 PDF_TEMPLATE_INVALID;幂等写入。

参数

名称类型必填说明
pdfstring
必填
PDF 输入:URL、base64 数据或已存储的 pdf_id。
degrees0 | 90 | 180 | 270可选旋转角度,取值 0、90、180 或 270。
default: 90
pagesnumber[]可选限定旋转的页码(1 起始);省略则旋转全部页面。
idempotency_keystring可选可选去重 key;相同重试将返回同一结果。

返回

PdfDocument { pdf_id, url, source }
名称类型说明
pdf_idstringPDF document的唯一标识符
pattern: ^pdf_[A-Za-z0-9]{20,}$
urlstring资源或端点 URL
size_bytesinteger资源大小(字节)
≥ 0
page_countintegerpages in the document数量
≥ 1
sha256string资源内容的 SHA-256 哈希
pattern: ^[a-f0-9]{64}$
created_atstring资源创建时间(ISO 8601)
format: date-time
retention_daysinteger | nulldays to retain this resource数量
≥ 0
source"html" | "markdown" | "template" | "ocr" | "mutate" | "convert" | "compress" | "encrypt" | "redact" | "form"PDF 来源(upload、url、html)

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/pdf/rotate \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"pdf": "sample"}'

2.15pdf.redact

POST /v1/pdf/redact

按区域或正则模式不可逆地涂黑内容;幂等写入,idempotency_key 用于重试去重。

参数

名称类型必填说明
pdfstring
必填
PDF 输入:URL、base64 数据或已存储的 pdf_id。
regionsArray<{ page; x; y; width; height }>可选需涂黑的矩形区域列表(含页码与坐标尺寸)。
patternsstring[]可选用于匹配并涂黑敏感内容的正则模式列表。
idempotency_keystring可选可选去重 key;相同重试将返回同一结果。

返回

PdfDocument { pdf_id, url, source }
名称类型说明
pdf_idstringPDF document的唯一标识符
pattern: ^pdf_[A-Za-z0-9]{20,}$
urlstring资源或端点 URL
size_bytesinteger资源大小(字节)
≥ 0
page_countintegerpages in the document数量
≥ 1
sha256string资源内容的 SHA-256 哈希
pattern: ^[a-f0-9]{64}$
created_atstring资源创建时间(ISO 8601)
format: date-time
retention_daysinteger | nulldays to retain this resource数量
≥ 0
source"html" | "markdown" | "template" | "ocr" | "mutate" | "convert" | "compress" | "encrypt" | "redact" | "form"PDF 来源(upload、url、html)

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/pdf/redact \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"pdf": "sample"}'

2.16pdf.sign

POST /v1/pdf/sign

为 PDF 应用 PKCS#7 / PAdES 数字签名;证书/私钥 PEM 头无效返回 PDF_SIGN_CERT_INVALID;幂等写入。

参数

名称类型必填说明
pdfstring
必填
PDF 输入:URL、base64 数据或已存储的 pdf_id。
cert_pemstring
必填
签名证书的 PEM 文本(须含有效 PEM 头)。
key_pemstring
必填
签名私钥的 PEM 文本(须含有效 PEM 头)。
reasonstring可选签名原因(可选,写入签名元数据)。
locationstring可选签名地点(可选,写入签名元数据)。
retention_daysnumber可选签名产物的保留天数(可选)。
≥ 0
idempotency_keystring可选可选去重 key;相同重试将返回同一结果。

返回

SignedPdfDocument { pdf_id, url, signed_at, signer }
名称类型说明
pdf_idstringPDF document的唯一标识符
pattern: ^pdf_[A-Za-z0-9]{20,}$
urlstring资源或端点 URL
size_bytesinteger资源大小(字节)
≥ 0
page_countintegerpages in the document数量
≥ 1
sha256string资源内容的 SHA-256 哈希
pattern: ^[a-f0-9]{64}$
created_atstring资源创建时间(ISO 8601)
format: date-time
retention_daysinteger | nulldays to retain this resource数量
≥ 0
signedbooleanPDF 是否已数字签名
signer_common_namestring从签名证书提取的 CN(通用名)。
signed_atstringPDF 签名时间(ISO 8601)
format: date-time
reasonstring | null当前状态或操作原因
locationstring | nullPDF 签名地点

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/pdf/sign \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"pdf": "sample", "cert_pem": "sample", "key_pem": "sample"}'

2.17pdf.verify

POST /v1/pdf/verify

根据证书校验已签名 PDF 的签名有效性;只读无副作用;cert_pem 必填。

参数

名称类型必填说明
signed_pdfstring
必填
已签名的 PDF 输入:URL、base64 数据或已存储的 pdf_id。
cert_pemstring
必填
用于校验签名的证书 PEM 文本。

返回

SignatureVerification { valid, signer, signed_at }
名称类型说明
validboolean仅当每个签名均经 cert_pem 验证且文档完整时为 true。
signaturesobject[]数字签名验证结果
signatures[].signer_common_namestring-
signatures[].validboolean签名密码学验证有效。
signatures[].intactboolean自此签名后文档未被修改。
signatures[].signed_atstring | null-
format: date-time
signatures[].reasonstring | null-

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/pdf/verify \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"signed_pdf": "sample", "cert_pem": "sample"}'

2.18pdf.job.get

GET /v1/pdf/job/get/{job_id}

按 job_id 查询异步 PDF 作业的状态与结果。

参数

名称类型必填说明
job_idstring
必填
异步 PDF 作业标识符。

返回

PdfJob { job_id, status, result, error }
名称类型说明
job_idstringasync job的唯一标识符
status"queued" | "running" | "completed" | "failed"当前资源状态
resultobject | nullstatus="completed" 时填充(PdfDocument 或 PdfDocumentListResult)。
errorstring | nullstatus="failed" 时填充。

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/pdf/job/get/JOB_ID \
  -H "Authorization: Bearer $INFRAI_API_KEY"

2.19pdf.template.create

POST /v1/pdf/template/create

创建可复用的 HTML PDF 模板;幂等写入,idempotency_key 用于重试去重。

参数

名称类型必填说明
namestring
必填
模板名称。
htmlstring
必填
模板的 HTML 内容,可含变量占位符。
vars_schemaobject可选模板变量的 JSON Schema(可选),用于校验渲染入参。
idempotency_keystring可选可选去重 key;相同重试将返回同一结果。

返回

PdfTemplate { template_id, name, created_at }
名称类型说明
template_idstring用于渲染的模板标识符
namestring资源的可读名称
htmlstring邮件的 HTML 正文
vars_schemaobject | null描述所需模板变量的 JSON Schema。
created_atstring资源创建时间(ISO 8601)
format: date-time

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/pdf/template/create \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "example", "html": "<h1>Hello from infrai</h1>"}'

3. 全部能力

本模块全部已路由能力——完整的对外 REST 契约。上方方法是带讲解的入门示例,此表是完整参考。

pdf.compressPOST /v1/pdf/compress

Compress a PDF to reduce file size, using the global fast/balanced/quality processing mode; idempotent write.

参数 (4)
名称类型必填说明
pdfstring必填PDF input: URL, base64 data, or stored pdf_id.
mode"fast" | "balanced" | "quality"可选Compression effort vs fidelity; reuses the global processing mode axis.
default: "balanced"
idempotency_keystring | null可选Client-provided idempotency key; prevents duplicate execution on retry
storeboolean可选Opt in to RETAIN the produced PDF in Infrai's own store (default false = stateless passthrough: produce, return inline, keep nothing). When true, Infrai persists the document, bills a self-hosted storage line item and applies a retention TTL — and only then do pdf.list/get/delete see it.
default: false
pdf.convertPOST /v1/pdf/convert

Convert a PDF to another format; unsupported targets return PDF_CONVERT_UNSUPPORTED (422); idempotent write.

参数 (4)
名称类型必填说明
pdfstring必填PDF input: URL, base64 data, or stored pdf_id.
to"docx" | "xlsx" | "pptx" | "png" | "jpg" | "html"必填Target format. (SSOT: enums/PdfConvertTarget)
idempotency_keystring | null可选Client-provided idempotency key; prevents duplicate execution on retry
storeboolean可选Opt in to RETAIN the produced PDF in Infrai's own store (default false = stateless passthrough: produce, return inline, keep nothing). When true, Infrai persists the document, bills a self-hosted storage line item and applies a retention TTL — and only then do pdf.list/get/delete see it.
default: false
pdf.decryptPOST /v1/pdf/decrypt

Remove password protection from a PDF; wrong password returns PDF_DECRYPT_FAILED (403); idempotent write.

参数 (4)
名称类型必填说明
pdfstring必填PDF input: URL, base64 data, or stored pdf_id.
passwordstring必填Password to decrypt the document.
idempotency_keystring | null可选Client-provided idempotency key; prevents duplicate execution on retry
storeboolean可选Opt in to RETAIN the produced PDF in Infrai's own store (default false = stateless passthrough: produce, return inline, keep nothing). When true, Infrai persists the document, bills a self-hosted storage line item and applies a retention TTL — and only then do pdf.list/get/delete see it.
default: false
pdf.encryptPOST /v1/pdf/encrypt

Encrypt a PDF with a password and permission flags; idempotent write.

参数 (6)
名称类型必填说明
pdfstring必填PDF input: URL, base64 data, or stored pdf_id.
user_passwordstring | null可选Password required to open the document.
owner_passwordstring | null可选Password required to change permissions.
permissionsstring[] | null可选Allowed actions (e.g. print, copy, modify).
idempotency_keystring | null可选Client-provided idempotency key; prevents duplicate execution on retry
storeboolean可选Opt in to RETAIN the produced PDF in Infrai's own store (default false = stateless passthrough: produce, return inline, keep nothing). When true, Infrai persists the document, bills a self-hosted storage line item and applies a retention TTL — and only then do pdf.list/get/delete see it.
default: false
pdf.extract_imagesPOST /v1/pdf/extract_images

Extract embedded images from a PDF, returned as data: URIs; read-only, no side effects.

参数 (2)
名称类型必填说明
pdfstring必填PDF input: URL, base64 data, or stored pdf_id.
pagesinteger[] | null可选1-indexed pages to scan; null = all pages.
pdf.form.extractPOST /v1/pdf/form/extract

Read AcroForm field names and values from a PDF; read-only, no side effects.

参数 (1)
名称类型必填说明
pdfstring必填PDF input: URL, base64 data, or stored pdf_id.
pdf.form.fillPOST /v1/pdf/form/fill

Fill AcroForm fields, optionally flattening to a non-editable PDF; idempotent write.

参数 (5)
名称类型必填说明
pdfstring必填PDF input: URL, base64 data, or stored pdf_id.
fieldsobject必填Map of AcroForm field name -> value.
flattenboolean可选If true, flatten fields so they are no longer editable.
default: false
idempotency_keystring | null可选Client-provided idempotency key; prevents duplicate execution on retry
storeboolean可选Opt in to RETAIN the produced PDF in Infrai's own store (default false = stateless passthrough: produce, return inline, keep nothing). When true, Infrai persists the document, bills a self-hosted storage line item and applies a retention TTL — and only then do pdf.list/get/delete see it.
default: false
pdf.generatePOST /v1/pdf/generate

Generate a PDF from HTML, Markdown, inline template, or a stored template rendered with variables; idempotent write.

参数 (10)
名称类型必填说明
htmlstring | null可选Inline HTML source.
markdownstring | null可选Inline Markdown source.
template_htmlstring | null可选Inline HTML template rendered with template_vars.
template_idstring | null可选Stored template id; server loads its HTML and renders with `vars` (source='template').
template_varsobject | null可选Variables for template_html.
varsobject | null可选Variables for template_id rendering.
page_size"A4" | "A3" | "A5" | "Letter" | "Legal" | "Tabloid"可选Page size (e.g. A4, Letter)
orientation"portrait" | "landscape"可选Page orientation (portrait, landscape)
default: "portrait"
idempotency_keystring | null可选Client-provided idempotency key; prevents duplicate execution on retry
storeboolean可选Opt in to RETAIN the produced PDF in Infrai's own store (default false = stateless passthrough: produce, return inline, keep nothing). When true, Infrai persists the document, bills a self-hosted storage line item and applies a retention TTL — and only then do pdf.list/get/delete see it.
default: false
pdf.job.getGET /v1/pdf/job/get/{job_id}

Get the status and result of an asynchronous PDF job by job_id.

参数 (1)
名称类型必填说明
job_idstring必填Path parameter.
pdf.mergePOST /v1/pdf/merge

Concatenate multiple PDFs in order into a single document; idempotent write.

参数 (3)
名称类型必填说明
inputsstring[]必填Ordered list of PDF inputs (URL, base64, or stored pdf_id).
≥ 1 item
idempotency_keystring | null可选Client-provided idempotency key; prevents duplicate execution on retry
storeboolean可选Opt in to RETAIN the produced PDF in Infrai's own store (default false = stateless passthrough: produce, return inline, keep nothing). When true, Infrai persists the document, bills a self-hosted storage line item and applies a retention TTL — and only then do pdf.list/get/delete see it.
default: false
pdf.ocrPOST /v1/pdf/ocr

Run OCR on a scanned PDF; unsupported language returns PDF_OCR_LANG_UNSUPPORTED (400); idempotent write.

参数 (4)
名称类型必填说明
pdfstring必填PDF input: URL, base64 data, or stored pdf_id.
langstring可选OCR language code.
default: "eng"
quality"fast" | "balanced" | "quality"可选OCR effort vs accuracy; reuses the global processing mode axis.
default: "fast"
idempotency_keystring | null可选Client-provided idempotency key; prevents duplicate execution on retry
pdf.parsePOST /v1/pdf/parse

Extract text, outline, and metadata from a PDF for RAG ingestion; read-only, no side effects.

参数 (2)
名称类型必填说明
pdfstring必填PDF input: URL, base64 data, or stored pdf_id.
pagesinteger[] | null可选1-indexed pages to parse; null = all pages.
pdf.redactPOST /v1/pdf/redact

Irreversibly black out content by region or regex pattern; idempotent write.

参数 (5)
名称类型必填说明
pdfstring必填PDF input: URL, base64 data, or stored pdf_id.
regionsobject[] | null可选Explicit rectangular regions to redact.
patternsstring[] | null可选Regex patterns; matched text is redacted.
idempotency_keystring | null可选Client-provided idempotency key; prevents duplicate execution on retry
storeboolean可选Opt in to RETAIN the produced PDF in Infrai's own store (default false = stateless passthrough: produce, return inline, keep nothing). When true, Infrai persists the document, bills a self-hosted storage line item and applies a retention TTL — and only then do pdf.list/get/delete see it.
default: false
pdf.rotatePOST /v1/pdf/rotate

Rotate specified pages by 0, 90, 180, or 270 degrees; idempotent write.

参数 (5)
名称类型必填说明
pdfstring必填PDF input: URL, base64 data, or stored pdf_id.
degrees0 | 90 | 180 | 270可选Rotation angle in degrees
default: 90
pagesinteger[] | null可选1-indexed pages to rotate; null = all pages.
idempotency_keystring | null可选Client-provided idempotency key; prevents duplicate execution on retry
storeboolean可选Opt in to RETAIN the produced PDF in Infrai's own store (default false = stateless passthrough: produce, return inline, keep nothing). When true, Infrai persists the document, bills a self-hosted storage line item and applies a retention TTL — and only then do pdf.list/get/delete see it.
default: false
pdf.signPOST /v1/pdf/sign

Apply a PKCS#7 / PAdES digital signature to a PDF; invalid certificate returns PDF_SIGN_CERT_INVALID; idempotent write.

参数 (8)
名称类型必填说明
pdfstring必填PDF input: URL, base64 data, or stored pdf_id.
cert_pemstring必填Signing certificate, PEM-encoded.
key_pemstring必填Private key, PEM-encoded.
reasonstring | null可选Reason for the current state or action
locationstring | null可选Location where the PDF was signed
retention_daysinteger | null可选Number of days to retain this resource
≥ 0
idempotency_keystring | null可选Client-provided idempotency key; prevents duplicate execution on retry
storeboolean可选Opt in to RETAIN the produced PDF in Infrai's own store (default false = stateless passthrough: produce, return inline, keep nothing). When true, Infrai persists the document, bills a self-hosted storage line item and applies a retention TTL — and only then do pdf.list/get/delete see it.
default: false
pdf.splitPOST /v1/pdf/split

Split a PDF into multiple documents by 1-indexed inclusive page ranges; idempotent write.

参数 (4)
名称类型必填说明
rangesinteger[][]必填List of [start,end] page ranges, 1-indexed inclusive.
≥ 1 item
pdfstring必填PDF input: URL, base64 data, or stored pdf_id.
idempotency_keystring | null可选Client-provided idempotency key; prevents duplicate execution on retry
storeboolean可选Opt in to RETAIN the produced PDF in Infrai's own store (default false = stateless passthrough: produce, return inline, keep nothing). When true, Infrai persists the document, bills a self-hosted storage line item and applies a retention TTL — and only then do pdf.list/get/delete see it.
default: false
pdf.template.createPOST /v1/pdf/template/create

Create a reusable HTML PDF template; idempotent write.

参数 (4)
名称类型必填说明
namestring必填Human-readable name for this resource
htmlstring必填Template HTML with double-brace var placeholders.
vars_schemaobject | null可选JSON-Schema describing required template variables.
idempotency_keystring | null可选Client-provided idempotency key; prevents duplicate execution on retry
pdf.verifyPOST /v1/pdf/verify

Verify a signed PDF's signature validity against a certificate; read-only, no side effects.

参数 (2)
名称类型必填说明
signed_pdfstring必填Signed PDF input: URL, base64 data, or stored pdf_id.
cert_pemstring必填Certificate to verify against, PEM-encoded.
pdf.watermarkPOST /v1/pdf/watermark

Stamp a text and/or image watermark onto a PDF; idempotent write.

参数 (7)
名称类型必填说明
pdfstring必填PDF input: URL, base64 data, or stored pdf_id.
textstring | null可选Text watermark; one of text/image required.
imagestring | null可选Image watermark input (URL/base64); one of text/image required.
opacitynumber可选Watermark opacity (0.0 to 1.0)
0–1default: 0.3
position"center" | "top-left" | "top-right" | "bottom-left" | "bottom-right"可选Position for the watermark (e.g. top-left, center)
default: "center"
idempotency_keystring | null可选Client-provided idempotency key; prevents duplicate execution on retry
storeboolean可选Opt in to RETAIN the produced PDF in Infrai's own store (default false = stateless passthrough: produce, return inline, keep nothing). When true, Infrai persists the document, bills a self-hosted storage line item and applies a retention TTL — and only then do pdf.list/get/delete see it.
default: false

4. 完整示例

本模块的生产级端到端范例:先一次性配置,再运行业务流程,尽量覆盖本模块的多数 API。

单文件可运行 Python 程序(仅标准库、无 SDK):拷贝后填入 INFRAI_API_KEY 运行,即可按真实业务流逐步体验本模块核心 API——每一步都真实调用并计费,后续步骤复用前一步返回的真实字段。12 行 helper 就是全部集成代码。

python
#!/usr/bin/env python3
"""Infrai · pdf — runnable real-app example (single file, zero deps).

Copy this file, set your key, run it: every step is a REAL call to
api.infrai.cc, billed at the real (tiny) per-call price, printing the
live JSON response. Get a key at https://infrai.cc/login (Google/
GitHub sign-in grants $2 free credit); add funds at
https://infrai.cc/billing. No SDK — the 12-line helper below is the
entire integration."""
import json
import os
from urllib import error, request

KEY = os.environ.get("INFRAI_API_KEY") or "ifr_..."  # <- your key
BASE = "https://api.infrai.cc"


# Same raw HTTPS POST/GET as every per-method example on this page —
# wrapped once for reuse. There is nothing else to it: no SDK.
def infrai(method, path, body=None):
    req = request.Request(
        BASE + path, method=method,
        data=json.dumps(body).encode() if body is not None else None,
        headers={"Authorization": f"Bearer {KEY}",
                 "Content-Type": "application/json"})
    try:
        with request.urlopen(req, timeout=60) as r:
            return json.loads(r.read())
    except error.HTTPError as e:
        return json.loads(e.read())


def show(label, resp):
    print(f"\n== {label} ==")
    print(json.dumps(resp, indent=2, ensure_ascii=False))
    return resp


# 1) pdf.generate — POST /v1/pdf/generate · Generate a PDF from HTML, Markdown, inline template, or a stored template rendered with variables; idempotent write.  # NOTE: non-trivial real cost
r1 = show("pdf.generate", infrai("POST", "/v1/pdf/generate", {"html":"<h1>Invoice #42</h1>","page_size":"A4","orientation":"portrait"}))

# 2) pdf.merge — POST /v1/pdf/merge · Concatenate multiple PDFs in order into a single document; idempotent write.
r2 = show("pdf.merge", infrai("POST", "/v1/pdf/merge", {"inputs":["hello"]}))