情境:PDF檔,筆者在LINE討論串受限不支援上傳,但可接受JPEG圖檔;而PDF檔可能有數十張以上,如何手動截圖相當耗時。
解決方式:在AGY CLI環璄下,自己產製一個PDF2JPEG技能,(如同巨集程式呼叫),只要告訴PDF檔位置,外加PDF2JPEG技能,自動就可以完成轉檔作業。
安裝執行環境概念:
Poppler(開放源碼) 在 PDF → JPEG 轉換流程中的角色
- 讀取 PDF ,經由 Poppler 提供了 PDF 解析與渲染引擎,能將 PDF 的向量資訊、文字與圖形解碼成位圖( raster image| )的原始像素資料。
- 交給 ImageMagick | magick(ImageMagick)在背後會呼叫 Poppler 的 pdftoppm/pdfinfo 程式或其程式庫 API,取得每頁的位圖緩衝區。
- 產出 JPEG 圖檔, ImageMagick 再根據這些位圖資料執行縮放、品質設定等處理,最終寫出 JPEG 檔案。Poppler 充當「PDF 解碼器」的角色,負責把 PDF 轉成可被 ImageMagick 處理的像素資料;沒有它,ImageMagick 無法直接讀取 PDF頁面。
- 高品質渲染:保留文字、向量圖形的細節,轉換出的影像清晰度高。
• ## Overview PDF2JPEG技能
Convert a PDF document into individual JPEG images, one per page. The output files **inherit the original PDF filename** and are suffixed with a zero‑padded sequential number, matching the style of the existing `MM2JPEG` skill.
## Command Options
### Poppler (recommended)
```bash
pdftoppm -jpeg -r 300 "<input.pdf>" "<output-dir>/<base-name>-page-%03d"
- `<input.pdf>` – Full path to the source PDF.
- `<output-dir>` – Directory where JPEG files will be written.
- `<base-name>` – Automatically derived from the PDF filename (without extension).
- `-r 300` – DPI (300 dpi matches `MM2JPEG`).
- `-jpeg` – Output JPEG format.
- `-%03d` – Zero‑padded page index (001, 002, …).
### ImageMagick (fallback if Poppler unavailable)
```bash
magick -density 300 -quality 90 -strip "<input.pdf>" "<output-dir>/<base-name>-page-%03d.jpeg"
```
(後略)
相關參考資訊: