document-processor-api

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Nutrient Document Processing

Nutrient 文档处理

Use Nutrient DWS for managed document workflows where fidelity, compliance, or multi-step processing matters more than local-tool convenience.
当保真度、合规性或多步骤处理比本地工具便利性更重要时,使用Nutrient DWS进行托管文档工作流。

Setup

设置

  • Get a Nutrient DWS API key at https://dashboard.nutrient.io/sign_up/?product=processor.
  • Direct API calls use
    Authorization: Bearer $NUTRIENT_API_KEY
    .
    bash
    export NUTRIENT_API_KEY="nutr_sk_..."
  • MCP setups commonly use
    @nutrient-sdk/dws-mcp-server
    with
    NUTRIENT_DWS_API_KEY
    .
  • Scripts live in
    scripts/
    relative to this SKILL.md. Use the directory containing this SKILL.md as the working directory:
    bash
    cd <directory containing this SKILL.md> && uv run scripts/<script>.py --help
  • Page ranges use
    start:end
    with 0-based indexes and end-exclusive semantics. Negative indexes count from the end.
  • 在https://dashboard.nutrient.io/sign_up/?product=processor获取Nutrient DWS API密钥。
  • 直接API调用使用
    Authorization: Bearer $NUTRIENT_API_KEY
    。
    bash
    export NUTRIENT_API_KEY="nutr_sk_..."
  • MCP设置通常结合
    NUTRIENT_DWS_API_KEY
    使用
    @nutrient-sdk/dws-mcp-server
    。
  • 脚本位于本SKILL.md相对路径的
    scripts/
    目录下。将包含本SKILL.md的目录作为工作目录:
    bash
    cd <directory containing this SKILL.md> && uv run scripts/<script>.py --help
  • 页面范围使用
    start:end
    格式,采用0起始索引且不包含结束索引。负索引从文档末尾开始计数。

When to use

使用场景

  • Generate PDFs from HTML templates, uploaded assets, or remote URLs.
  • Convert Office, HTML, image, and PDF files between supported formats.
  • OCR scans and extract text, tables, or key-value pairs.
  • Redact PII, watermark, sign, fill forms, merge, split, rotate, flatten, or encrypt PDFs.
  • Produce delivery targets like PDF/A, PDF/UA, optimized PDFs, or linearized PDFs.
  • Check credits before large, batch, or AI-heavy runs.
  • 从HTML模板、上传资源或远程URL生成PDF。
  • 在支持的格式之间转换Office、HTML、图片和PDF文件。
  • 对扫描件进行OCR识别,并提取文本、表格或键值对。
  • 对PDF进行PII脱敏、添加水印、数字签名、填写表单、合并、拆分、旋转、扁平化或加密。
  • 生成PDF/A、PDF/UA、优化PDF或线性化PDF等交付格式。
  • 在执行大规模、批量或AI密集型任务前检查可用额度。

Tool preference

工具优先级

  1. Prefer
    scripts/*.py
    for covered single-operation workflows.
  2. Use
    assets/templates/custom-workflow-template.py
    for multi-step jobs that should still run through the Python client.
  3. Use the modular
    references/
    docs and direct API payloads for capabilities that do not yet have a dedicated helper script, especially HTML/URL generation and compliance tuning.
  4. Use local PDF utilities only for lightweight inspection. Use Nutrient when output fidelity or compliance matters.
  1. 对于已覆盖的单操作工作流,优先使用
    scripts/*.py
    脚本。
  2. 对于多步骤任务,若仍需通过Python客户端运行,使用
    assets/templates/custom-workflow-template.py
    。
  3. 对于尚无专用辅助脚本的功能(尤其是HTML/URL生成和合规性调优),使用模块化的
    references/
    文档和直接API负载。
  4. 仅将本地PDF工具用于轻量级检查。当输出保真度或合规性很重要时,使用Nutrient。

Single-operation scripts

单操作脚本

  • convert.py
    -> convert between
    pdf
    ,
    pdfa
    ,
    pdfua
    ,
    docx
    ,
    xlsx
    ,
    pptx
    ,
    png
    ,
    jpeg
    ,
    webp
    ,
    html
    , and
    markdown
  • merge.py
    -> merge multiple files into one PDF
  • split.py
    -> split one PDF into multiple PDFs by page ranges
  • add-pages.py
    -> append blank pages
  • delete-pages.py
    -> remove specific pages
  • duplicate-pages.py
    -> reorder or duplicate pages into a new PDF
  • rotate.py
    -> rotate selected pages
  • ocr.py
    -> OCR scanned PDFs or images
  • extract-text.py
    -> extract text to JSON
  • extract-table.py
    -> extract tables
  • extract-key-value-pairs.py
    -> extract key-value pairs
  • watermark-text.py
    -> apply a text watermark
  • redact-ai.py
    -> detect and apply AI-powered redactions
  • sign.py
    -> digitally sign a local PDF
  • password-protect.py
    -> write encrypted output PDFs
  • optimize.py
    -> apply optimization and linearization-style options via JSON
  • convert.py
    -> 在
    pdf
    、
    pdfa
    、
    pdfua
    、
    docx
    、
    xlsx
    、
    pptx
    、
    png
    、
    jpeg
    、
    webp
    、
    html
    和
    markdown
    格式之间转换
  • merge.py
    -> 将多个文件合并为单个PDF
  • split.py
    -> 按页面范围将单个PDF拆分为多个PDF
  • add-pages.py
    -> 添加空白页
  • delete-pages.py
    -> 删除指定页面
  • duplicate-pages.py
    -> 重新排序或复制页面以生成新PDF
  • rotate.py
    -> 旋转选定页面
  • ocr.py
    -> 对扫描PDF或图片进行OCR识别
  • extract-text.py
    -> 将文本提取为JSON格式
  • extract-table.py
    -> 提取表格
  • extract-key-value-pairs.py
    -> 提取键值对
  • watermark-text.py
    -> 添加文本水印
  • redact-ai.py
    -> 检测并应用AI驱动的脱敏处理
  • sign.py
    -> 对本地PDF进行数字签名
  • password-protect.py
    -> 生成加密的输出PDF
  • optimize.py
    -> 通过JSON应用优化和线性化类选项

Multi-Step Workflow Rule

多步骤工作流规则

Do not add new committed pipeline scripts under
scripts/
.
When the user asks for multiple operations in one run:
  1. Copy
    assets/templates/custom-workflow-template.py
    to a temporary location such as
    /tmp/ndp-workflow-<task>.py
    .
  2. Implement the combined workflow in that temporary script.
  3. Run it with
    uv run /tmp/ndp-workflow-<task>.py ...
    .
  4. Return generated output files.
  5. Delete the temporary script unless the user explicitly asks to keep it.
不要在
scripts/
目录下添加新的已提交管道脚本。
当用户要求在一次运行中执行多个操作时:
  1. 将
    assets/templates/custom-workflow-template.py
    复制到临时位置,例如
    /tmp/ndp-workflow-<task>.py
    。
  2. 在该临时脚本中实现组合工作流。
  3. 使用
    uv run /tmp/ndp-workflow-<task>.py ...
    运行脚本。
  4. 返回生成的输出文件。
  5. 除非用户明确要求保留,否则删除临时脚本。

PDF Requirements

PDF要求

  • split.py
    requires a multi-page PDF and cannot extract ranges from a single-page document.
  • delete-pages.py
    must retain at least one page and cannot delete the entire document.
  • sign.py
    only accepts local file paths for the main PDF.
  • split.py
    需要多页PDF,无法从单页文档中提取页面范围。
  • delete-pages.py
    必须至少保留一页,不能删除整个文档。
  • sign.py
    仅接受主PDF的本地文件路径。

Decision rules

决策规则

  • Prefer a helper script when one already covers the requested operation cleanly.
  • If you control the source markup, prefer HTML generation over browser print workflows.
  • Use remote
    file.url
    inputs when the source already lives at a stable URL and you want to avoid local uploads.
  • Use
    output.type
    for conversion and finalization targets. Use
    actions
    for transformations when building direct API payloads.
  • OCR before text extraction, key-value extraction, or semantic redaction on scans.
  • Prefer preset or regex redaction when the target is explicit. Use AI redaction only for contextual or natural-language requests.
  • Use the PDF manipulation reference for merge, split, rotate, flatten, and page-range workflows instead of inferring those payloads from conversion examples.
  • Treat PDF/A and PDF/UA as compliance targets, not cosmetic export formats. Choose the target up front and validate final artifacts when requirements are contractual.
  • For PDF/UA, clean born-digital inputs and structured HTML usually tag better than rasterized or flattened source PDFs.
  • For delivery optimization, linearize or optimize unsigned output artifacts instead of mutating already signed files.
  • When the user asks for multiple steps, keep destructive or final steps late in the sequence. Use the workflow recipes when ordering is ambiguous.
  • 如果已有辅助脚本能清晰覆盖请求的操作,优先使用该脚本。
  • 如果您控制源标记,优先使用HTML生成而非浏览器打印工作流。
  • 当源文件已存储在稳定URL且您希望避免本地上传时,使用远程
    file.url
    输入。
  • 转换和最终化目标使用
    output.type
    。构建直接API负载时,使用
    actions
    进行转换操作。
  • 对扫描件进行文本提取、键值提取或语义脱敏前,先执行OCR识别。
  • 当目标明确时,优先使用预设或正则表达式脱敏。仅在处理上下文或自然语言请求时使用AI脱敏。
  • 对于合并、拆分、旋转、扁平化和页面范围工作流,使用PDF操作参考文档,而非从转换示例中推断负载。
  • 将PDF/A和PDF/UA视为合规目标,而非美化导出格式。提前选择目标格式,当要求具有合约性质时,验证最终产物。
  • 对于PDF/UA,原生数字输入和结构化HTML通常比光栅化或扁平化的源PDF标记效果更好。
  • 针对交付优化,对未签名的输出产物进行线性化或优化,而非修改已签名文件。
  • 当用户要求多个步骤时,将破坏性或最终步骤放在序列后期。当顺序不明确时,使用工作流配方。

Anti-patterns

反模式

  • Do not OCR born-digital PDFs just because the task mentions extraction. Extract first and OCR only if the text layer is missing.
  • Do not flatten forms or annotations until the user confirms the artifact no longer needs to stay editable.
  • Do not sign, archive, or linearize intermediate working files. Keep those as final-delivery steps.
  • Do not promise PDF/A or PDF/UA compliance without a validation step when the requirement is contractual.
  • Do not commit temporary workflow scripts under
    scripts/
    .
  • 不要仅仅因为任务提到提取就对原生数字PDF进行OCR识别。先提取文本,仅当文本层缺失时再进行OCR。
  • 除非用户确认产物不再需要保持可编辑状态,否则不要扁平化表单或注释。
  • 不要对中间工作文件进行签名、归档或线性化处理。将这些操作保留为最终交付步骤。
  • 当合规要求具有合约性质时,不要在未进行验证步骤的情况下承诺PDF/A或PDF/UA合规性。
  • 不要将临时工作流脚本提交到
    scripts/
    目录下。

Reference map

参考映射

Read only what you need:
  • references/request-basics.md
    -> endpoint model, auth, multipart vs JSON, credits, limits, and errors
  • references/generation-and-conversion.md
    -> HTML/URL generation and format conversion
  • references/pdf-manipulation.md
    -> merge, split, page-range, rotate, and flatten workflows
  • references/extraction-and-ocr.md
    -> OCR, text extraction, tables, and key-value workflows
  • references/security-signing-and-forms.md
    -> redaction, watermarking, signatures, forms, and passwords
  • references/compliance-and-optimization.md
    -> PDF/A, PDF/UA, optimization, and linearization
  • references/workflow-recipes.md
    -> end-to-end sequencing patterns for common business document workflows
按需阅读:
  • references/request-basics.md
    -> 端点模型、认证、多部分表单与JSON、额度、限制和错误
  • references/generation-and-conversion.md
    -> HTML/URL生成和格式转换
  • references/pdf-manipulation.md
    -> 合并、拆分、页面范围、旋转和平铺工作流
  • references/extraction-and-ocr.md
    -> OCR、文本提取、表格和键值对工作流
  • references/security-signing-and-forms.md
    -> 脱敏、水印、签名、表单和密码
  • references/compliance-and-optimization.md
    -> PDF/A、PDF/UA、优化和线性化
  • references/workflow-recipes.md
    -> 常见业务文档工作流的端到端序列模式

Rules

规则

  • Fail fast when required arguments are missing.
  • Write outputs to explicit paths and print created files.
  • Do not log secrets.
  • All client methods are async and should run via
    asyncio.run(main())
    .
  • If import fails, install dependency with
    uv add nutrient-dws
    .
  • 当缺少必要参数时快速失败。
  • 将输出写入明确路径并打印已创建的文件。
  • 不要记录机密信息。
  • 所有客户端方法均为异步,应通过
    asyncio.run(main())
    运行。
  • 如果导入失败,使用
    uv add nutrient-dws
    安装依赖。

Security Hardening Addendum

安全加固补充说明

  • Prefer a pinned, preinstalled MCP server binary over runtime package fetches.
    • Preferred:
      npm i -g @nutrient-sdk/dws-mcp-server@<pinned-version>
    • Avoid unpinned runtime fetch in production paths.
  • Never store
    NUTRIENT_DWS_API_KEY
    in committed JSON config files.
    • Use process env injection at runtime (shell/export, secrets manager, or host env).
  • Restrict file access with
    SANDBOX_PATH
    to the minimum required working directory.
  • Before enabling MCP mode in production, verify package provenance and lock version.
  • 优先使用固定版本的预安装MCP服务器二进制文件,而非运行时包获取。
    • 推荐:
      npm i -g @nutrient-sdk/dws-mcp-server@<pinned-version>
    • 避免在生产路径中使用未固定版本的运行时获取。
  • 不要将
    NUTRIENT_DWS_API_KEY
    存储在已提交的JSON配置文件中。
    • 在运行时通过进程环境注入(shell/export、密钥管理器或主机环境)。
  • 使用
    SANDBOX_PATH
    限制文件访问至所需的最小工作目录。
  • 在生产环境中启用MCP模式前,验证包来源并锁定版本。