Files
SnapOtter/apps/docs/zh-TW/tools/image/image-to-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

3.8 KiB
Raw Blame History

description, i18n_source_hash, i18n_provenance, i18n_output_hash
description i18n_source_hash i18n_provenance i18n_output_hash
將一張或多張圖片合併為 PDF 文件,並提供頁面尺寸、方向與目標檔案大小選項。 f659c7e7f56b human 0cc07a4a39ea

圖片轉 PDF

將一張或多張圖片合併為 PDF 文件。支援多種頁面尺寸、方向、邊界,以及透過品質調整達成的選填檔案大小目標。

API 端點

POST /api/v1/tools/image/image-to-pdf

接受包含一個或多個圖片檔案的 multipart 表單資料,以及一個 JSON settings 欄位。

參數

參數 型別 必填 預設值 說明
pageSize string "A4" 頁面尺寸:A4LetterA3A5
orientation string "portrait" 頁面方向:portraitlandscape
margin number 20 頁面邊界(點,0-500
targetSize object - 目標檔案大小限制(見下方)
collate boolean true 將所有圖片合併為一份 PDF。若為 false,則每張圖片產生一份 PDF。

Target Size 物件

欄位 型別 必填 說明
value number 目標大小數值
unit string 單位:KBMB

最小目標大小為 50 KB。

範例請求

基本多圖 PDF

curl -X POST http://localhost:1349/api/v1/tools/image/image-to-pdf \
  -H "Authorization: Bearer si_your-api-key" \
  -F "file=@page1.jpg" \
  -F "file=@page2.jpg" \
  -F "file=@page3.jpg" \
  -F 'settings={"pageSize": "A4", "orientation": "portrait", "margin": 20}'

含檔案大小目標:

curl -X POST http://localhost:1349/api/v1/tools/image/image-to-pdf \
  -H "Authorization: Bearer si_your-api-key" \
  -F "file=@scan1.jpg" \
  -F "file=@scan2.jpg" \
  -F 'settings={"pageSize": "Letter", "targetSize": {"value": 2, "unit": "MB"}}'

每張圖片一份 PDF

curl -X POST http://localhost:1349/api/v1/tools/image/image-to-pdf \
  -H "Authorization: Bearer si_your-api-key" \
  -F "file=@photo1.jpg" \
  -F "file=@photo2.jpg" \
  -F 'settings={"collate": false}'

範例回應(合併)

{
  "jobId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "downloadUrl": "/api/v1/download/a1b2c3d4-e5f6-7890-abcd-ef1234567890/images.pdf",
  "originalSize": 5000000,
  "processedSize": 1200000,
  "pages": 3
}

範例回應(未合併)

{
  "jobId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "downloadUrl": "/api/v1/download/a1b2c3d4-e5f6-7890-abcd-ef1234567890/images.zip",
  "originalSize": 5000000,
  "processedSize": 2400000,
  "pages": 2,
  "collated": false
}

範例回應(含目標大小)

{
  "jobId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "downloadUrl": "/api/v1/download/a1b2c3d4-e5f6-7890-abcd-ef1234567890/images.pdf",
  "originalSize": 10000000,
  "processedSize": 2000000,
  "pages": 5,
  "compression": {
    "targetRequested": 2097152,
    "targetMet": true,
    "jpegQuality": 72
  }
}

注意事項

  • 圖片會置中於頁面,並在保留長寬比的前提下縮放以套入邊界內。圖片絕不會被放大。
  • collatefalse 時,每張圖片會成為獨立的 PDF 檔案,下載為包含所有 PDF 的 ZIP 封存檔。
  • 目標大小功能會對 JPEG 品質等級(10-95)進行迭代二分搜尋,找出在預算內符合的最佳品質。
  • 透明圖片在嵌入 PDF 前會平整化為白色。
  • 支援的輸入格式:JPEG、PNG、WebP、AVIF、TIFF、GIF、HEIC、RAW、PSD、SVG 等。
  • 嵌入前會自動套用 EXIF 方向資訊。