Skip to content

PDF

Generate, merge, split, OCR and watermark PDFs.

1. Overview

Base path: https://api.infrai.cc/v1/pdf
Auth header: 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. Methods (19)

2.1pdf.generate

POST /v1/pdf/generate

Generate a PDF from HTML, a URL or a template.

Parameters

NameTypeRequiredDescription
htmlstringOptionalHTML source to render.
urlstringOptionalSource URL to render or operate on.
template_idstringOptionalTemplate id to render instead of a body.
format"A4" | "Letter" | "Legal"OptionalPage size.
orientation"portrait" | "landscape"OptionalPage orientation.
default: "portrait"
idempotency_keystringOptionalOptional dedup key; identical retries return the same result.

Returns

PdfResult { pdf_url, bytes, pages }
NameTypeDescription
pdf_idstringUnique identifier for this PDF document
pattern: ^pdf_[A-Za-z0-9]{20,}$
urlstringURL for this resource or endpoint
size_bytesintegerSize of the resource in bytes
≥ 0
page_countintegerNumber of pages in the document
≥ 1
sha256stringSHA-256 hash of the resource content
pattern: ^[a-f0-9]{64}$
created_atstringISO 8601 timestamp when this resource was created
format: date-time
retention_daysinteger | nullNumber of days to retain this resource
≥ 0
source"html" | "markdown" | "template" | "ocr" | "mutate" | "convert" | "compress" | "encrypt" | "redact" | "form"Source of the PDF (upload, url, html)

Example

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

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

Merge several PDFs into one.

Parameters

NameTypeRequiredDescription
urlsstring[]
Required
List of PDF URLs to merge.

Returns

PdfResult
NameTypeDescription
pdf_idstringUnique identifier for this PDF document
pattern: ^pdf_[A-Za-z0-9]{20,}$
urlstringURL for this resource or endpoint
size_bytesintegerSize of the resource in bytes
≥ 0
page_countintegerNumber of pages in the document
≥ 1
sha256stringSHA-256 hash of the resource content
pattern: ^[a-f0-9]{64}$
created_atstringISO 8601 timestamp when this resource was created
format: date-time
retention_daysinteger | nullNumber of days to retain this resource
≥ 0
source"html" | "markdown" | "template" | "ocr" | "mutate" | "convert" | "compress" | "encrypt" | "redact" | "form"Source of the PDF (upload, url, html)

Example

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

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

Split a PDF by page ranges.

Parameters

NameTypeRequiredDescription
urlstring
Required
Source URL to render or operate on.
rangesstring[]
Required
Page ranges, e.g. 1-3.
≥ 1 item

Returns

{ parts: PdfResult[] }
NameTypeDescription
pdf_idstringUnique identifier for this PDF document
pattern: ^pdf_[A-Za-z0-9]{20,}$
urlstringURL for this resource or endpoint
size_bytesintegerSize of the resource in bytes
≥ 0
page_countintegerNumber of pages in the document
≥ 1
sha256stringSHA-256 hash of the resource content
pattern: ^[a-f0-9]{64}$
created_atstringISO 8601 timestamp when this resource was created
format: date-time
retention_daysinteger | nullNumber of days to retain this resource
≥ 0
source"html" | "markdown" | "template" | "ocr" | "mutate" | "convert" | "compress" | "encrypt" | "redact" | "form"Source of the PDF (upload, url, html)

Example

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

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

Extract text from a PDF via OCR.

Parameters

NameTypeRequiredDescription
urlstring
Required
Source URL to render or operate on.
languagestringOptionalLanguage hint, e.g. en or zh.

Returns

{ text, pages: Array<{ text }> }
NameTypeDescription
pdf_idstringUnique identifier for this PDF document
pattern: ^pdf_[A-Za-z0-9]{20,}$
text_per_pagestring[]Extracted text content per page
confidence_avgnumber | nullAverage confidence score of the OCR result
0–1
lang_detectedstring | nullDetected language of the document
duration_msintegerDuration of the operation in milliseconds
≥ 0
engine"chromium" | "unstructured_io" | "aws_textract" | "google_doc_ai" | "paddle_ocr"Processing engine used (e.g. tesseract, google-vision)

Example

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

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

Apply a text or image watermark to a PDF.

Parameters

NameTypeRequiredDescription
urlstring
Required
Source URL to render or operate on.
textstringOptionalWatermark text.
opacitynumberOptionalWatermark opacity from 0 to 1.
0–1default: 0.3

Returns

PdfResult
NameTypeDescription
pdf_idstringUnique identifier for this PDF document
pattern: ^pdf_[A-Za-z0-9]{20,}$
urlstringURL for this resource or endpoint
size_bytesintegerSize of the resource in bytes
≥ 0
page_countintegerNumber of pages in the document
≥ 1
sha256stringSHA-256 hash of the resource content
pattern: ^[a-f0-9]{64}$
created_atstringISO 8601 timestamp when this resource was created
format: date-time
retention_daysinteger | nullNumber of days to retain this resource
≥ 0
source"html" | "markdown" | "template" | "ocr" | "mutate" | "convert" | "compress" | "encrypt" | "redact" | "form"Source of the PDF (upload, url, html)

Example

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

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 用于重试去重。

Parameters

NameTypeRequiredDescription
pdfstring
Required
PDF 输入:URL、base64 数据或已存储的 pdf_id。
mode"fast" | "balanced" | "quality"Optional压缩力度与保真的权衡,复用全局处理档位(fast/balanced/quality)。
default: "balanced"
idempotency_keystringOptionalOptional dedup key; identical retries return the same result.

Returns

PdfDocument { pdf_id, url, bytes, page_count, source }
NameTypeDescription
pdf_idstringUnique identifier for this PDF document
pattern: ^pdf_[A-Za-z0-9]{20,}$
urlstringURL for this resource or endpoint
size_bytesintegerSize of the resource in bytes
≥ 0
page_countintegerNumber of pages in the document
≥ 1
sha256stringSHA-256 hash of the resource content
pattern: ^[a-f0-9]{64}$
created_atstringISO 8601 timestamp when this resource was created
format: date-time
retention_daysinteger | nullNumber of days to retain this resource
≥ 0
source"html" | "markdown" | "template" | "ocr" | "mutate" | "convert" | "compress" | "encrypt" | "redact" | "form"Source of the PDF (upload, url, html)

Example

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

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;幂等写入。

Parameters

NameTypeRequiredDescription
pdfstring
Required
PDF 输入:URL、base64 数据或已存储的 pdf_id。
to"docx" | "xlsx" | "pptx" | "png" | "jpg" | "html"
Required
目标格式(如 docx、png、jpg 等)。
idempotency_keystringOptionalOptional dedup key; identical retries return the same result.

Returns

PdfDocument (multi-page image targets return PdfDocumentListResult)
NameTypeDescription
pdf_idstringUnique identifier for this PDF document
pattern: ^pdf_[A-Za-z0-9]{20,}$
urlstringURL for this resource or endpoint
size_bytesintegerSize of the resource in bytes
≥ 0
page_countintegerNumber of pages in the document
≥ 1
sha256stringSHA-256 hash of the resource content
pattern: ^[a-f0-9]{64}$
created_atstringISO 8601 timestamp when this resource was created
format: date-time
retention_daysinteger | nullNumber of days to retain this resource
≥ 0
source"html" | "markdown" | "template" | "ocr" | "mutate" | "convert" | "compress" | "encrypt" | "redact" | "form"Source of the PDF (upload, url, html)

Example

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

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。

Parameters

NameTypeRequiredDescription
pdfstring
Required
PDF 输入:URL、base64 数据或已存储的 pdf_id。
pagesnumber[]Optional限定解析的页码(1 起始);省略则解析全部页面。

Returns

PdfParseResult { text, pages, outline, metadata }
NameTypeDescription
pdf_idstringUnique identifier for this PDF document
pattern: ^pdf_[A-Za-z0-9]{20,}$
text_per_pagestring[]Extracted text content per page
outlineobject[]Document outline / table of contents
outline[].titlestring-
outline[].pageinteger-
metadataobject | nullArbitrary key-value metadata attached to this resource
languagestring | nullDetected language of the text

Example

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

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 形式返回;只读无副作用。

Parameters

NameTypeRequiredDescription
pdfstring
Required
PDF 输入:URL、base64 数据或已存储的 pdf_id。
pagesnumber[]Optional限定提取图片的页码(1 起始);省略则提取全部页面。

Returns

PdfExtractImagesResult { images: ExtractedImage[] }
NameTypeDescription
imagesobject[]List of generated or processed images
images[].pageintegerPage number (1-based)
≥ 1
images[].image_urlstringURL to the extracted image
images[].widthintegerWidth of the image in pixels
≥ 1
images[].heightintegerHeight of the image in pixels
≥ 1
images[].mime_typestring | nullMIME type of the resource

Example

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

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 表单字段名与取值;只读无副作用。

Parameters

NameTypeRequiredDescription
pdfstring
Required
PDF 输入:URL、base64 数据或已存储的 pdf_id。

Returns

PdfFormExtractResult { fields }
NameTypeDescription
fieldsobject[]Extracted form fields
fields[].namestring-
fields[].typestringAcroForm field type (text, checkbox, radio, choice, signature).
fields[].valuestring | boolean | null-

Example

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

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 用于重试去重。

Parameters

NameTypeRequiredDescription
pdfstring
Required
PDF 输入:URL、base64 数据或已存储的 pdf_id。
fieldsRecord<string, string>
Required
字段名到取值的映射,用于填充表单。
flattenbooleanOptional为 true 时将填充值压平,使表单不可再编辑。
default: false
idempotency_keystringOptionalOptional dedup key; identical retries return the same result.

Returns

PdfDocument { pdf_id, url, page_count, source }
NameTypeDescription
pdf_idstringUnique identifier for this PDF document
pattern: ^pdf_[A-Za-z0-9]{20,}$
urlstringURL for this resource or endpoint
size_bytesintegerSize of the resource in bytes
≥ 0
page_countintegerNumber of pages in the document
≥ 1
sha256stringSHA-256 hash of the resource content
pattern: ^[a-f0-9]{64}$
created_atstringISO 8601 timestamp when this resource was created
format: date-time
retention_daysinteger | nullNumber of days to retain this resource
≥ 0
source"html" | "markdown" | "template" | "ocr" | "mutate" | "convert" | "compress" | "encrypt" | "redact" | "form"Source of the PDF (upload, url, html)

Example

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

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 用于重试去重。

Parameters

NameTypeRequiredDescription
pdfstring
Required
PDF 输入:URL、base64 数据或已存储的 pdf_id。
user_passwordstringOptional打开文档所需的用户密码。
owner_passwordstringOptional用于权限控制的所有者密码。
permissionsstring[]Optional允许的操作权限列表(如 print、copy 等)。
idempotency_keystringOptionalOptional dedup key; identical retries return the same result.

Returns

PdfDocument { pdf_id, url, source }
NameTypeDescription
pdf_idstringUnique identifier for this PDF document
pattern: ^pdf_[A-Za-z0-9]{20,}$
urlstringURL for this resource or endpoint
size_bytesintegerSize of the resource in bytes
≥ 0
page_countintegerNumber of pages in the document
≥ 1
sha256stringSHA-256 hash of the resource content
pattern: ^[a-f0-9]{64}$
created_atstringISO 8601 timestamp when this resource was created
format: date-time
retention_daysinteger | nullNumber of days to retain this resource
≥ 0
source"html" | "markdown" | "template" | "ocr" | "mutate" | "convert" | "compress" | "encrypt" | "redact" | "form"Source of the PDF (upload, url, html)

Example

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

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);幂等写入。

Parameters

NameTypeRequiredDescription
pdfstring
Required
PDF 输入:URL、base64 数据或已存储的 pdf_id。
passwordstring
Required
用于解密文档的密码。
idempotency_keystringOptionalOptional dedup key; identical retries return the same result.

Returns

PdfDocument { pdf_id, url, source }
NameTypeDescription
pdf_idstringUnique identifier for this PDF document
pattern: ^pdf_[A-Za-z0-9]{20,}$
urlstringURL for this resource or endpoint
size_bytesintegerSize of the resource in bytes
≥ 0
page_countintegerNumber of pages in the document
≥ 1
sha256stringSHA-256 hash of the resource content
pattern: ^[a-f0-9]{64}$
created_atstringISO 8601 timestamp when this resource was created
format: date-time
retention_daysinteger | nullNumber of days to retain this resource
≥ 0
source"html" | "markdown" | "template" | "ocr" | "mutate" | "convert" | "compress" | "encrypt" | "redact" | "form"Source of the PDF (upload, url, html)

Example

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

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;幂等写入。

Parameters

NameTypeRequiredDescription
pdfstring
Required
PDF 输入:URL、base64 数据或已存储的 pdf_id。
degrees0 | 90 | 180 | 270Optional旋转角度,取值 0、90、180 或 270。
default: 90
pagesnumber[]Optional限定旋转的页码(1 起始);省略则旋转全部页面。
idempotency_keystringOptionalOptional dedup key; identical retries return the same result.

Returns

PdfDocument { pdf_id, url, source }
NameTypeDescription
pdf_idstringUnique identifier for this PDF document
pattern: ^pdf_[A-Za-z0-9]{20,}$
urlstringURL for this resource or endpoint
size_bytesintegerSize of the resource in bytes
≥ 0
page_countintegerNumber of pages in the document
≥ 1
sha256stringSHA-256 hash of the resource content
pattern: ^[a-f0-9]{64}$
created_atstringISO 8601 timestamp when this resource was created
format: date-time
retention_daysinteger | nullNumber of days to retain this resource
≥ 0
source"html" | "markdown" | "template" | "ocr" | "mutate" | "convert" | "compress" | "encrypt" | "redact" | "form"Source of the PDF (upload, url, html)

Example

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

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 用于重试去重。

Parameters

NameTypeRequiredDescription
pdfstring
Required
PDF 输入:URL、base64 数据或已存储的 pdf_id。
regionsArray<{ page; x; y; width; height }>Optional需涂黑的矩形区域列表(含页码与坐标尺寸)。
patternsstring[]Optional用于匹配并涂黑敏感内容的正则模式列表。
idempotency_keystringOptionalOptional dedup key; identical retries return the same result.

Returns

PdfDocument { pdf_id, url, source }
NameTypeDescription
pdf_idstringUnique identifier for this PDF document
pattern: ^pdf_[A-Za-z0-9]{20,}$
urlstringURL for this resource or endpoint
size_bytesintegerSize of the resource in bytes
≥ 0
page_countintegerNumber of pages in the document
≥ 1
sha256stringSHA-256 hash of the resource content
pattern: ^[a-f0-9]{64}$
created_atstringISO 8601 timestamp when this resource was created
format: date-time
retention_daysinteger | nullNumber of days to retain this resource
≥ 0
source"html" | "markdown" | "template" | "ocr" | "mutate" | "convert" | "compress" | "encrypt" | "redact" | "form"Source of the PDF (upload, url, html)

Example

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

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;幂等写入。

Parameters

NameTypeRequiredDescription
pdfstring
Required
PDF 输入:URL、base64 数据或已存储的 pdf_id。
cert_pemstring
Required
签名证书的 PEM 文本(须含有效 PEM 头)。
key_pemstring
Required
签名私钥的 PEM 文本(须含有效 PEM 头)。
reasonstringOptional签名原因(可选,写入签名元数据)。
locationstringOptional签名地点(可选,写入签名元数据)。
retention_daysnumberOptional签名产物的保留天数(可选)。
≥ 0
idempotency_keystringOptionalOptional dedup key; identical retries return the same result.

Returns

SignedPdfDocument { pdf_id, url, signed_at, signer }
NameTypeDescription
pdf_idstringUnique identifier for this PDF document
pattern: ^pdf_[A-Za-z0-9]{20,}$
urlstringURL for this resource or endpoint
size_bytesintegerSize of the resource in bytes
≥ 0
page_countintegerNumber of pages in the document
≥ 1
sha256stringSHA-256 hash of the resource content
pattern: ^[a-f0-9]{64}$
created_atstringISO 8601 timestamp when this resource was created
format: date-time
retention_daysinteger | nullNumber of days to retain this resource
≥ 0
signedbooleanWhether the PDF has been digitally signed
signer_common_namestringCN extracted from the signing certificate.
signed_atstringISO 8601 timestamp when the PDF was signed
format: date-time
reasonstring | nullReason for the current state or action
locationstring | nullLocation where the PDF was signed

Example

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

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 必填。

Parameters

NameTypeRequiredDescription
signed_pdfstring
Required
已签名的 PDF 输入:URL、base64 数据或已存储的 pdf_id。
cert_pemstring
Required
用于校验签名的证书 PEM 文本。

Returns

SignatureVerification { valid, signer, signed_at }
NameTypeDescription
validbooleanTrue iff every signature validates against cert_pem and the document is intact.
signaturesobject[]Digital signature verification results
signatures[].signer_common_namestring-
signatures[].validbooleanSignature cryptographically valid.
signatures[].intactbooleanDocument unmodified since this signature.
signatures[].signed_atstring | null-
format: date-time
signatures[].reasonstring | null-

Example

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

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 作业的状态与结果。

Parameters

NameTypeRequiredDescription
job_idstring
Required
异步 PDF 作业标识符。

Returns

PdfJob { job_id, status, result, error }
NameTypeDescription
job_idstringUnique identifier for this async job
status"queued" | "running" | "completed" | "failed"Current status of this resource
resultobject | nullPopulated when status='completed' (a PdfDocument or PdfDocumentListResult).
errorstring | nullPopulated when status='failed'.

Example

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

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 用于重试去重。

Parameters

NameTypeRequiredDescription
namestring
Required
模板名称。
htmlstring
Required
模板的 HTML 内容,可含变量占位符。
vars_schemaobjectOptional模板变量的 JSON Schema(可选),用于校验渲染入参。
idempotency_keystringOptionalOptional dedup key; identical retries return the same result.

Returns

PdfTemplate { template_id, name, created_at }
NameTypeDescription
template_idstringIdentifier of the template used for rendering
namestringHuman-readable name for this resource
htmlstringHTML body of the email
vars_schemaobject | nullJSON-Schema describing required template variables.
created_atstringISO 8601 timestamp when this resource was created
format: date-time

Example

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

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. All capabilities

Every routed capability in this module — the complete public REST contract. The methods above are the guided walkthrough; this index is the full reference.

pdf.compressPOST /v1/pdf/compress

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

Parameters (4)
NameTypeRequiredDescription
pdfstringRequiredPDF input: URL, base64 data, or stored pdf_id.
mode"fast" | "balanced" | "quality"OptionalCompression effort vs fidelity; reuses the global processing mode axis.
default: "balanced"
idempotency_keystring | nullOptionalClient-provided idempotency key; prevents duplicate execution on retry
storebooleanOptionalOpt 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.

Parameters (4)
NameTypeRequiredDescription
pdfstringRequiredPDF input: URL, base64 data, or stored pdf_id.
to"docx" | "xlsx" | "pptx" | "png" | "jpg" | "html"RequiredTarget format. (SSOT: enums/PdfConvertTarget)
idempotency_keystring | nullOptionalClient-provided idempotency key; prevents duplicate execution on retry
storebooleanOptionalOpt 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.

Parameters (4)
NameTypeRequiredDescription
pdfstringRequiredPDF input: URL, base64 data, or stored pdf_id.
passwordstringRequiredPassword to decrypt the document.
idempotency_keystring | nullOptionalClient-provided idempotency key; prevents duplicate execution on retry
storebooleanOptionalOpt 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.

Parameters (6)
NameTypeRequiredDescription
pdfstringRequiredPDF input: URL, base64 data, or stored pdf_id.
user_passwordstring | nullOptionalPassword required to open the document.
owner_passwordstring | nullOptionalPassword required to change permissions.
permissionsstring[] | nullOptionalAllowed actions (e.g. print, copy, modify).
idempotency_keystring | nullOptionalClient-provided idempotency key; prevents duplicate execution on retry
storebooleanOptionalOpt 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.

Parameters (2)
NameTypeRequiredDescription
pdfstringRequiredPDF input: URL, base64 data, or stored pdf_id.
pagesinteger[] | nullOptional1-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.

Parameters (1)
NameTypeRequiredDescription
pdfstringRequiredPDF 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.

Parameters (5)
NameTypeRequiredDescription
pdfstringRequiredPDF input: URL, base64 data, or stored pdf_id.
fieldsobjectRequiredMap of AcroForm field name -> value.
flattenbooleanOptionalIf true, flatten fields so they are no longer editable.
default: false
idempotency_keystring | nullOptionalClient-provided idempotency key; prevents duplicate execution on retry
storebooleanOptionalOpt 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.

Parameters (10)
NameTypeRequiredDescription
htmlstring | nullOptionalInline HTML source.
markdownstring | nullOptionalInline Markdown source.
template_htmlstring | nullOptionalInline HTML template rendered with template_vars.
template_idstring | nullOptionalStored template id; server loads its HTML and renders with `vars` (source='template').
template_varsobject | nullOptionalVariables for template_html.
varsobject | nullOptionalVariables for template_id rendering.
page_size"A4" | "A3" | "A5" | "Letter" | "Legal" | "Tabloid"OptionalPage size (e.g. A4, Letter)
orientation"portrait" | "landscape"OptionalPage orientation (portrait, landscape)
default: "portrait"
idempotency_keystring | nullOptionalClient-provided idempotency key; prevents duplicate execution on retry
storebooleanOptionalOpt 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.

Parameters (1)
NameTypeRequiredDescription
job_idstringRequiredPath parameter.
pdf.mergePOST /v1/pdf/merge

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

Parameters (3)
NameTypeRequiredDescription
inputsstring[]RequiredOrdered list of PDF inputs (URL, base64, or stored pdf_id).
≥ 1 item
idempotency_keystring | nullOptionalClient-provided idempotency key; prevents duplicate execution on retry
storebooleanOptionalOpt 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.

Parameters (4)
NameTypeRequiredDescription
pdfstringRequiredPDF input: URL, base64 data, or stored pdf_id.
langstringOptionalOCR language code.
default: "eng"
quality"fast" | "balanced" | "quality"OptionalOCR effort vs accuracy; reuses the global processing mode axis.
default: "fast"
idempotency_keystring | nullOptionalClient-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.

Parameters (2)
NameTypeRequiredDescription
pdfstringRequiredPDF input: URL, base64 data, or stored pdf_id.
pagesinteger[] | nullOptional1-indexed pages to parse; null = all pages.
pdf.redactPOST /v1/pdf/redact

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

Parameters (5)
NameTypeRequiredDescription
pdfstringRequiredPDF input: URL, base64 data, or stored pdf_id.
regionsobject[] | nullOptionalExplicit rectangular regions to redact.
patternsstring[] | nullOptionalRegex patterns; matched text is redacted.
idempotency_keystring | nullOptionalClient-provided idempotency key; prevents duplicate execution on retry
storebooleanOptionalOpt 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.

Parameters (5)
NameTypeRequiredDescription
pdfstringRequiredPDF input: URL, base64 data, or stored pdf_id.
degrees0 | 90 | 180 | 270OptionalRotation angle in degrees
default: 90
pagesinteger[] | nullOptional1-indexed pages to rotate; null = all pages.
idempotency_keystring | nullOptionalClient-provided idempotency key; prevents duplicate execution on retry
storebooleanOptionalOpt 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.

Parameters (8)
NameTypeRequiredDescription
pdfstringRequiredPDF input: URL, base64 data, or stored pdf_id.
cert_pemstringRequiredSigning certificate, PEM-encoded.
key_pemstringRequiredPrivate key, PEM-encoded.
reasonstring | nullOptionalReason for the current state or action
locationstring | nullOptionalLocation where the PDF was signed
retention_daysinteger | nullOptionalNumber of days to retain this resource
≥ 0
idempotency_keystring | nullOptionalClient-provided idempotency key; prevents duplicate execution on retry
storebooleanOptionalOpt 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.

Parameters (4)
NameTypeRequiredDescription
rangesinteger[][]RequiredList of [start,end] page ranges, 1-indexed inclusive.
≥ 1 item
pdfstringRequiredPDF input: URL, base64 data, or stored pdf_id.
idempotency_keystring | nullOptionalClient-provided idempotency key; prevents duplicate execution on retry
storebooleanOptionalOpt 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.

Parameters (4)
NameTypeRequiredDescription
namestringRequiredHuman-readable name for this resource
htmlstringRequiredTemplate HTML with double-brace var placeholders.
vars_schemaobject | nullOptionalJSON-Schema describing required template variables.
idempotency_keystring | nullOptionalClient-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.

Parameters (2)
NameTypeRequiredDescription
signed_pdfstringRequiredSigned PDF input: URL, base64 data, or stored pdf_id.
cert_pemstringRequiredCertificate to verify against, PEM-encoded.
pdf.watermarkPOST /v1/pdf/watermark

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

Parameters (7)
NameTypeRequiredDescription
pdfstringRequiredPDF input: URL, base64 data, or stored pdf_id.
textstring | nullOptionalText watermark; one of text/image required.
imagestring | nullOptionalImage watermark input (URL/base64); one of text/image required.
opacitynumberOptionalWatermark opacity (0.0 to 1.0)
0–1default: 0.3
position"center" | "top-left" | "top-right" | "bottom-left" | "bottom-right"OptionalPosition for the watermark (e.g. top-left, center)
default: "center"
idempotency_keystring | nullOptionalClient-provided idempotency key; prevents duplicate execution on retry
storebooleanOptionalOpt 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. End-to-end example

A production-style walkthrough of this module: configure once, then run the flow. It exercises most of the module's APIs.

A copy-paste-runnable single-file Python program (stdlib only, no SDK): set your INFRAI_API_KEY, run it, and walk this module's core flow with REAL billed calls — later steps reuse real fields returned by earlier ones. The 12-line helper is the entire integration.

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"]}))