Generate, merge, split, OCR and watermark PDFs.
Overview
Base path:
/v1/pdfPython namespace:
infra.pdftext
# Python
from infrai import infra
# TypeScript
import { InfraiClient } from "@infrai/sdk";
const client = new InfraiClient({ apiKey: process.env.INFRAI_API_KEY! });
// → client.pdfMethods
pdf.generate
POST /v1/pdf/generate
Generate a PDF from HTML, a URL or a template.
Python
python
infra.pdf.generate(html=None, url=None, template_id=None, format="A4", orientation="portrait", idempotency_key=None)TypeScript
typescript
client.pdf.generate(opts: PdfGenerateOptions): Promise<PdfResult>Parameters
| Name | Type | Required | Description |
|---|---|---|---|
html | string | Optional | HTML source to render. |
url | string | Optional | Source URL to render or operate on. |
template_id | string | Optional | Template id to render instead of a body. |
format | "A4" | "Letter" | "Legal" | Optional | Page size. |
orientation | "portrait" | "landscape" | Optional | Page orientation. |
idempotency_key | string | Optional | Optional dedup key; identical retries return the same result. |
Returns
PdfResult { pdf_url, bytes, pages }Example
一次性前置(每个范例都假定已完成):
bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...python
from infrai import infra
# Pass exactly one source: inline html, a remote url, or a template_id.
doc = infra.pdf.generate(
html="<h1>Invoice #1042</h1><p>Total due: $42.00</p>",
format="A4",
orientation="portrait",
)
print("pdf url:", doc.get("url") or doc.get("pdf_url"))pdf.merge
POST /v1/pdf/merge
Merge several PDFs into one.
Python
python
infra.pdf.merge(urls=[...])TypeScript
typescript
client.pdf.merge(opts: { urls }): Promise<PdfResult>Parameters
| Name | Type | Required | Description |
|---|---|---|---|
urls | string[] | Required | List of PDF URLs to merge. |
Returns
PdfResultExample
一次性前置(每个范例都假定已完成):
bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...python
from infrai import infra
out = infra.pdf.merge(urls=["https://ex.com/a.pdf", "https://ex.com/b.pdf"])
print("merged url:", out.get("url") or out.get("pdf_url"))pdf.split
POST /v1/pdf/split
Split a PDF by page ranges.
Python
python
infra.pdf.split(url=..., ranges=[...])TypeScript
typescript
client.pdf.split(opts: { url, ranges }): Promise<{ parts }>Parameters
| Name | Type | Required | Description |
|---|---|---|---|
url | string | Required | Source URL to render or operate on. |
ranges | string[] | Required | Page ranges, e.g. 1-3. |
Returns
{ parts: PdfResult[] }Example
一次性前置(每个范例都假定已完成):
bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...python
from infrai import infra
res = infra.pdf.split(url="https://ex.com/doc.pdf", ranges=["1-3", "4-"])
print("parts:", len(res.get("parts", [])))pdf.ocr
POST /v1/pdf/ocr
Extract text from a PDF via OCR.
Python
python
infra.pdf.ocr(url=..., language=None)TypeScript
typescript
client.pdf.ocr(opts: { url, language? }): Promise<{ text, pages }>Parameters
| Name | Type | Required | Description |
|---|---|---|---|
url | string | Required | Source URL to render or operate on. |
language | string | Optional | Language hint, e.g. en or zh. |
Returns
{ text, pages: Array<{ text }> }Example
一次性前置(每个范例都假定已完成):
bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...python
from infrai import infra
res = infra.pdf.ocr(url="https://ex.com/scan.pdf", language="en")
print(res.get("text", "")[:200])pdf.watermark
POST /v1/pdf/watermark
Apply a text or image watermark to a PDF.
Python
python
infra.pdf.watermark(url=..., text=None, image_url=None, opacity=None)TypeScript
typescript
client.pdf.watermark(opts): Promise<PdfResult>Parameters
| Name | Type | Required | Description |
|---|---|---|---|
url | string | Required | Source URL to render or operate on. |
text | string | Optional | Watermark text. |
opacity | number | Optional | Watermark opacity from 0 to 1. |
Returns
PdfResultExample
一次性前置(每个范例都假定已完成):
bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...python
from infrai import infra
out = infra.pdf.watermark(url="https://ex.com/doc.pdf", text="CONFIDENTIAL", opacity=0.2)
print("watermarked url:", out.get("url") or out.get("pdf_url"))