Files
SnapOtter/apps/docs/zh-CN/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 c96018e728d8

Compress PDF

通过对嵌入的图像进行降采样来缩减 PDF 文件大小。可在质量滑块和目标文件大小之间选择。

API Endpoint

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

接受包含一个 PDF 文件和一个 JSON settings 字段的 multipart 表单数据。

Parameters

Parameter Type Required Default Description
mode string No "quality" 压缩模式:qualitytargetSize
quality integer No 75 压缩质量,1-100(值越高压缩越少)。在 quality 模式下使用
targetSizeKb number No - 以千字节为单位的目标文件大小。在 targetSize 模式下使用

Example Request

按质量压缩:

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}'

Example Response

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

Notes

  • quality 模式下,值越低生成的文件越小,但图像退化越严重。
  • targetSize 模式下,二分查找会找到能够容纳所请求大小的最高 DPI。
  • 如果压缩会使文件变大,则原始字节将原样返回。
  • 文本和矢量内容不受影响;只有嵌入的栅格图像会被降采样。