👁️ 184
👍 60
📅 2026-06-13 收录
🔄 2026-06-13 更新
Nutrient Document Processing (Universal Agent Skill)

Nutrient Document Processing (Universal Agent Skill)

📁 Nutrient Document Processing (Universal Agent Skill)

正文内容

营养文档处理(通用智能体技能)

适用于 Claude Code / Codex / Gemini / Cursor / Windsurf 等非 OpenClaw 智能体。使用 [Nutrient DWS Processor API](https://www.nutrient.io/api/) 对文档进行处理、格式转换、内容提取、OCR 识别、敏感信息脱敏、数字签名及各类操作。

配置

您需要一个 Nutrient DWS API 密钥。可免费在 注册获取。

方式一:MCP 服务器(推荐)

若您的智能体支持 MCP(Model Context Protocol),请使用 Nutrient DWS MCP Server。它将全部功能封装为原生工具供直接调用。

配置您的 MCP 客户端(例如 claude_desktop_config.json.mcp.json):

{
  "mcpServers": {
    "nutrient-dws": {
      "command": "npx",
      "args": ["-y", "@nutrient-sdk/dws-mcp-server"],
      "env": {
        "NUTRIENT_DWS_API_KEY": "YOUR_API_KEY",
        "SANDBOX_PATH": "/path/to/working/directory"
      }
    }
  }
}

随后即可直接调用 MCP 工具(例如 convert_to_pdfextract_textredact 等)。

方式二:直连 API(curl)

对于不支持 MCP 的智能体,可直接调用 API:

export NUTRIENT_API_KEY="your_api_key_here"

所有请求均以 multipart POST 方式发送至 https://api.nutrient.io/build,并需在请求体中包含 instructions JSON 字段。

安全边界

  • 本技能会将文档上传至 Nutrient DWS API(api.nutrient.io)进行处理。文档可能包含敏感数据,请确保您 Nutrient 账户的数据处理策略符合您的合规要求。
  • 本技能不会访问除显式传入待处理文件以外的任何本地文件。
  • 本技能不会在当前会话之外存储 API 密钥或凭据。
  • MCP 服务器模式(npx @nutrient-sdk/dws-mcp-server)会在运行时从 npm 下载官方 Nutrient MCP 服务器包。
  • 所有 API 调用均需提供明确的 API 密钥 —— 不支持匿名访问。

支持的操作

1. 文档格式转换

支持 PDF、DOCX、XLSX、PPTX、HTML 及图像格式之间的相互转换。

HTML 转 PDF:

curl -X POST https://api.nutrient.io/build \
  -H "Authorization: Bearer $NUTRIENT_API_KEY" \
  -F "index.html=@index.html" \
  -F 'instructions={"parts":[{"html":"index.html"}]}' \
  -o output.pdf

DOCX 转 PDF:

curl -X POST https://api.nutrient.io/build \
  -H "Authorization: Bearer $NUTRIENT_API_KEY" \
  -F "document.docx=@document.docx" \
  -F 'instructions={"parts":[{"file":"document.docx"}]}' \
  -o output.pdf

PDF 转 DOCX / XLSX / PPTX:

curl -X POST https://api.nutrient.io/build \
  -H "Authorization: Bearer $NUTRIENT_API_KEY" \
  -F "document.pdf=@document.pdf" \
  -F 'instructions={"parts":[{"file":"document.pdf"}],"output":{"type":"docx"}}' \
  -o output.docx

图像转 PDF:

curl -X POST https://api.nutrient.io/build \
  -H "Authorization: Bearer $NUTRIENT_API_KEY" \
  -F "image.jpg=@image.jpg" \
  -F 'instructions={"parts":[{"file":"image.jpg"}]}' \
  -o output.pdf

2. 文本与结构化数据提取

提取纯文本:

curl -X POST https://api.nutrient.io/build \
  -H "Authorization: Bearer $NUTRIENT_API_KEY" \
  -F "document.pdf=@document.pdf" \
  -F 'instructions={"parts":[{"file":"document.pdf"}],"output":{"type":"text"}}' \
  -o output.txt

提取表格(输出为 JSON、CSV 或 Excel):

curl -X POST https://api.nutrient.io/build \
  -H "Authorization: Bearer $NUTRIENT_API_KEY" \
  -F "document.pdf=@document.pdf" \
  -F 'instructions={"parts":[{"file":"document.pdf"}],"output":{"type":"xlsx"}}' \
  -o tables.xlsx

提取键值对(Key-Value Pairs):

curl -X POST https://api.nutrient.io/build \
  -H "Authorization: Bearer $NUTRIENT_API_KEY" \
  -F "document.pdf=@document.pdf" \
  -F 'instructions={"parts":[{"file":"document.pdf"}],"actions":[{"type":"extraction","strategy":"key-values"}]}' \
  -o result.json

3. 扫描文档 OCR 处理

对扫描版 PDF 或图像执行 OCR,生成含可选中文本的可搜索 PDF。

curl -X POST https://api.nutrient.io/build \
  -H "Authorization: Bearer $NUTRIENT_API_KEY" \
  -F "scanned.pdf=@scanned.pdf" \
  -F 'instructions={"parts":[{"file":"scanned.pdf"}],"actions":[{"type":"ocr","language":"english"}]}' \
  -o searchable.pdf

支持的语言包括:englishgermanfrenchspanishitalianportuguesedutchswedishdanishnorwegianfinnishpolishczechturkishjapanesekoreanchinese-simplifiedchinese-traditionalarabichebrewthaihindirussian 等。

4. 敏感信息脱敏(Redaction)

基于预设规则的脱敏:

curl -X POST https://api.nutrient.io/build \
  -H "Authorization: Bearer $NUTRIENT_API_KEY" \
  -F "document.pdf=@document.pdf" \
  -F 'instructions={"parts":[{"file":"document.pdf"}],"actions":[{"type":"redaction","strategy":"preset","preset":"social-security-number"}]}' \
  -o redacted.pdf

可用预设规则:social-security-numbercredit-card-numberemail-addressnorth-american-phone-numberinternational-phone-numberdateurlipv4ipv6mac-addressus-zip-codevintime

基于正则表达式的脱敏:

curl -X POST https://api.nutrient.io/build \
  -H "Authorization: Bearer $NUTRIENT_API_KEY" \
  -F "document.pdf=@document.pdf" \
  -F 'instructions={"parts":[{"file":"document.pdf"}],"actions":[{"type":"redaction","strategy":"regex","regex":"\\b[A-Z]{2}\\d{6}\\b"}]}' \
  -o redacted.pdf

AI 驱动的 PII 脱敏:

curl -X POST https://api.nutrient.io/build \
  -H "Authorization: Bearer $NUTRIENT_API_KEY" \
  -F "document.pdf=@document.pdf" \
  -F 'instructions={"parts":[{"file":"document.pdf"}],"actions":[{"type":"ai_redaction","criteria":"All personally identifiable information"}]}' \
  -o redacted.pdf

criteria 字段支持自然语言描述(例如 "Names and phone numbers""Protected health information""Financial account numbers")。

5. 添加水印

文字水印:

curl -X POST https://api.nutrient.io/build \
  -H "Authorization: Bearer $NUTRIENT_API_KEY" \
  -F "document.pdf=@document.pdf" \
  -F 'instructions={"parts":[{"file":"document.pdf"}],"actions":[{"type":"watermark","text":"CONFIDENTIAL","fontSize":48,"fontColor":"#FF0000","opacity":0.5,"rotation":45,"width":"50%","height":"50%"}]}' \
  -o watermarked.pdf

图片水印:

curl -X POST https://api.nutrient.io/build \
  -H "Authorization: Bearer $NUTRIENT_API_KEY" \
  -F "document.pdf=@document.pdf" \
  -F "logo.png=@logo.png" \
  -F 'instructions={"parts":[{"file":"document.pdf"}],"actions":[{"type":"watermark","imagePath":"logo.png","width":"30%","height":"30%","opacity":0.3}]}' \
  -o watermarked.pdf

6. 数字签名

使用 CMS 签名签署 PDF:

curl -X POST https://api.nutrient.io/build \
  -H "Authorization: Bearer $NUTRIENT_API_KEY" \
  -F "document.pdf=@document.pdf" \
  -F 'instructions={"parts":[{"file":"document.pdf"}],"actions":[{"type":"sign","signatureType":"cms","signerName":"John Doe","reason":"Approval","location":"New York"}]}' \
  -o signed.pdf

使用 CAdES-B-LT(支持长期有效性验证)签名:

curl -X POST https://api.nutrient.io/build \
  -H "Authorization: Bearer $NUTRIENT_API_KEY" \
  -F "document.pdf=@document.pdf" \
  -F 'instructions={"parts":[{"file":"document.pdf"}],"actions":[{"type":"sign","signatureType":"cades","cadesLevel":"b-lt","signerName":"Jane Smith"}]}' \
  -o signed.pdf

7. 表单自动填充(Instant JSON 格式)

使用 Instant JSON 格式向 PDF 表单字段填入数据:

curl -X POST https://api.nutrient.io/build \
  -H "Authorization: Bearer $NUTRIENT_API_KEY" \
  -F "form.pdf=@form.pdf" \
  -F 'instructions={"parts":[{"file":"form.pdf"}],"actions":[{"type":"fillForm","fields":[{"name":"firstName","value":"John"},{"name":"lastName","value":"Doe"},{"name":"email","value":"john@example.com"}]}]}' \
  -o filled.pdf

8. PDF 合并与拆分

合并多个 PDF 文件:

curl -X POST https://api.nutrient.io/build \
  -H "Authorization: Bearer $NUTRIENT_API_KEY" \
  -F "doc1.pdf=@doc1.pdf" \
  -F "doc2.pdf=@doc2.pdf" \
  -F 'instructions={"parts":[{"file":"doc1.pdf"},{"file":"doc2.pdf"}]}' \
  -o merged.pdf

提取指定页码范围:

curl -X POST https://api.nutrient.io/build \
  -H "Authorization: Bearer $NUTRIENT_API_KEY" \
  -F "document.pdf=@document.pdf" \
  -F 'instructions={"parts":[{"file":"document.pdf","pages":{"start":0,"end":4}}]}' \
  -o pages1-5.pdf

9. 将 PDF 页面渲染为图像

curl -X POST https://api.nutrient.io/build \
  -H "Authorization: Bearer $NUTRIENT_API_KEY" \
  -F "document.pdf=@document.pdf" \
  -F 'instructions={"parts":[{"file":"document.pdf","pages":{"start":0,"end":0}}],"output":{"type":"png","dpi":300}}' \
  -o page1.png

10. 查询余额(Credits)

curl -X GET https://api.nutrient.io/credits \
  -H "Authorization: Bearer $NUTRIENT_API_KEY"

最佳实践

  1. 优先使用 MCP 服务器 —— 当您的智能体支持 MCP 时,该方式可自动处理文件 I/O、错误恢复与沙箱隔离。
  2. 设置 SANDBOX_PATH —— 限制文件访问范围至指定目录,增强安全性。
  3. 批量操作前检查余额 —— 避免因额度不足导致任务中断。
  4. 按需选用脱敏方式 —— 对复杂 PII 场景使用 AI 脱敏;对已知固定模式(如身份证号、邮箱)优先使用预设规则或正则表达式(速度更快、成本更低)。
  5. 组合多步操作 —— API 支持单次请求中串联多个动作(例如先 OCR 再脱敏)。

故障排查

问题 解决方案
401 Unauthorized 检查 API 密钥是否有效,且账户仍有可用额度
413 Payload Too Large 单个文件大小不得超过 100 MB
AI 脱敏响应缓慢 AI 分析耗时通常为 60–120 秒,属正常现象
OCR 识别质量差 尝试更换 language 参数,或提升原始扫描图像质量
提取结果缺失文本 对扫描文档,请先执行 OCR 操作

更多信息

  • [完整 API 参考文档](references/REFERENCE.md) —— 含详细端点说明、参数定义与错误码
  • [API Playground](https://dashboard.nutrient.io/processor-api/playground/) —— 交互式 API 测试环境
  • [API 文档中心](https://www.nutrient.io/guides/dws-processor/) —— 官方操作指南与教程
  • [MCP Server 代码仓库](https://github.com/PSPDFKit/nutrient-dws-mcp-server) —— 源码与问题追踪