Files
SnapOtter/apps/docs/zh-TW/tools/pdf/compress-pdf.md
T
SnapOtterandGitHub 4963ab3bbd feat(docs-i18n): translate all documentation into 20 languages
All 181 docs markdown files translated into 20 languages (apps/docs/<locale>/**). Companion to the i18n code PR; admin-merged because the file count exceeds GitHub's per-PR CI trigger limit. Validated by pnpm i18n:check (all surfaces, 0 stale/missing) and a clean all-locale docs build.
2026-07-11 13:52:47 +08:00

2.0 KiB

description, i18n_source_hash, i18n_provenance, i18n_output_hash
description i18n_source_hash i18n_provenance i18n_output_hash
透過壓縮內嵌影像來縮小 PDF 檔案大小。 a8bb0baaca25 human 429b2e896a58

壓縮 PDF

透過降低內嵌影像的取樣率來縮小 PDF 檔案大小。可選擇使用品質滑桿或指定目標檔案大小。

API 端點

POST /api/v1/tools/pdf/compress-pdf

接受包含 PDF 檔案與 JSON settings 欄位的 multipart 表單資料。

參數

參數 類型 必填 預設值 說明
mode string "quality" 壓縮模式:qualitytargetSize
quality integer 75 壓縮品質,1-100(越高 = 壓縮越少)。用於 quality 模式
targetSizeKb number - 以 KB 為單位的目標檔案大小。用於 targetSize 模式

範例請求

依品質壓縮:

curl -X POST http://localhost:1349/api/v1/tools/pdf/compress-pdf \
  -H "Authorization: Bearer si_your-api-key" \
  -F "file=@document.pdf" \
  -F 'settings={"mode": "quality", "quality": 60}'

壓縮至目標大小:

curl -X POST http://localhost:1349/api/v1/tools/pdf/compress-pdf \
  -H "Authorization: Bearer si_your-api-key" \
  -F "file=@document.pdf" \
  -F 'settings={"mode": "targetSize", "targetSizeKb": 500}'

範例回應

{
  "jobId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "downloadUrl": "/api/v1/download/a1b2c3d4-e5f6-7890-abcd-ef1234567890/document.pdf",
  "originalSize": 5200000,
  "processedSize": 1800000
}

注意事項

  • quality 模式下,數值越低產生的檔案越小,但影像劣化越明顯。
  • targetSize 模式下,二元搜尋會找出符合所要求大小的最高 DPI。
  • 若壓縮反而會使檔案變大,則會原封不動地回傳原始位元組。
  • 文字與向量內容不受影響;只有內嵌的點陣影像會被降低取樣率。