使用 Nutrient DWS API 進行文件處理、格式轉換、OCR 文字辨識、資料擷取、敏感資訊遮蔽 (Redact)、數位簽署與表格填寫。支援 PDF、DOCX、XLSX、PPTX、HTML 和圖片格式。
Nutrient 文件處理 (Nutrient Document Processing)
注意: 此 Skill 整合了 Nutrient 的商業 API。在使用前請閱讀並同意其使用條款。
使用 Nutrient DWS Processor API 處理文件。支援格式轉換、擷取文字與表格、對掃描文件進行 OCR 光學字元辨識、遮蔽個人識別資訊 (PII)、新增浮水印、數位簽署以及填寫 PDF 表單。
設定步驟
前往 nutrient.io 取得免費 API 金鑰:
export NUTRIENT_API_KEY="pdf_live_..."
所有請求皆發送至 https://api.nutrient.io/build,採用 multipart POST 格式並包含一個 instructions JSON 欄位。
操作範例
轉換文件格式
# 將 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
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
# 將 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
支援的輸入格式:PDF, DOCX, XLSX, PPTX, DOC, XLS, PPT, PPS, PPSX, ODT, RTF, HTML, JPG, PNG, TIFF, HEIC, GIF, WebP, SVG, TGA, EPS。
擷取文字與資料
# 擷取純文字
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
# 將表格擷取並匯出為 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
對掃描文件進行 OCR 文字辨識
# 透過 OCR 轉換為可搜尋的 PDF(支援 100+ 種語言)
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
語言支援:支援超過 100 種語言的 ISO 639-2 代碼(例如:eng, deu, fra, spa, jpn, kor, chi_sim, chi_tra, ara, hin, rus)。輸入完整語言名稱如 english 或 german 亦可運作。完整支援代碼請參閱 OCR 語言支援對照表。
遮蔽敏感資訊 (Redact)
# 依預設樣式遮蔽 (如社會安全碼 SSN、電子郵件)
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","strategyOptions":{"preset":"social-security-number"}},{"type":"redaction","strategy":"preset","strategyOptions":{"preset":"email-address"}}]}' \
-o redacted.pdf
# 依正規表示式 (Regex) 遮蔽
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","strategyOptions":{"regex":"\\b[A-Z]{2}\\d{6}\\b"}}]}' \
-o redacted.pdf
預設集選項:social-security-number, email-address, credit-card-number, international-phone-number, north-american-phone-number, date, time, url, ipv4, ipv6, mac-address, us-zip-code, vin。
新增浮水印
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":72,"opacity":0.3,"rotation":-45}]}' \
-o watermarked.pdf
數位簽署
# 自我簽署 CMS 簽章
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"}]}' \
-o signed.pdf
填寫 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","formFields":{"name":"Jane Smith","email":"jane@example.com","date":"2026-02-06"}}]}' \
-o filled.pdf
MCP 伺服器 (替代方案)
若欲使用原生工具整合,可使用 MCP 伺服器代替 curl 方式:
{
"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"
}
}
}
}
適用場景
- 在不同格式之間轉換文件 (PDF, DOCX, XLSX, PPTX, HTML, 圖片)
- 從 PDF 中擷取純文字、表格或鍵值對 (Key-Value Pairs)
- 對掃描文件或圖片進行 OCR 文字辨識
- 在分享文件前遮蔽個人敏感資訊 (PII)
- 為草稿或機密文件新增浮水印
- 數位簽署合約或協議文件
- 以程式化方式自動填寫 PDF 表單






