360 Secure SkillHub
360 安全技能中心

pdf2jpg

基于 poppler-utils 中的 pdftoppm 将 PDF 逐页转换为 JPEG,支持指定首页与末页,输出文件名沿用 PDF 基名;附带脚本可把生成的 JPG 打包为 zip 便于分享。运行依赖 pdftoppm 可用并在 PATH 中,脚本会检查输入文件与依赖是否存在。

luohongq
luohongq
热度 46.60
最近更新 2026-05-11 17:34:59
分类:效率依赖:代码执行 / 读写文件应用场景:文件转换 / 自动化脚本 / 工作流

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add pdf2jpg
Metadata
name
pdf2jpg
description
Convert PDF files to JPEG images with pdftoppm, support optional page ranges, and bundle generated JPGs into a zip archive for sharing. Use when a user wants to turn a PDF into page images, extract selected pages, or package the results. Requires poppler-utils / pdftoppm.

pdf2jpg

Overview

Convert a PDF into JPEG page images using pdftoppm from poppler-utils, then optionally zip the generated JPGs.

Requirements

  • pdftoppm must be available in PATH
  • Install the poppler-utils package before running the scripts

Install poppler-utils

  • Debian / Ubuntu:

    sudo apt update
    sudo apt install -y poppler-utils
    
  • Windows:

    • Install Poppler via a package manager, then make pdftoppm.exe available in your PATH
    • Common options:
      • winget install -e --id oschwartz10612.Poppler
      • choco install poppler
      • scoop install poppler
  • macOS:

    brew install poppler
    

Standard workflow

  1. Convert the PDF with scripts/pdf2jpg.sh
  2. Bundle the output images with scripts/zip_jpgs.sh if needed
./scripts/pdf2jpg.sh input.pdf
./scripts/pdf2jpg.sh input.pdf 2 5
./scripts/zip_jpgs.sh input.pdf
./scripts/zip_jpgs.sh input.pdf /tmp/output.zip

Scripts

scripts/pdf2jpg.sh

  • Prompts for the PDF path if none is supplied
  • Verifies the input file exists
  • Verifies pdftoppm is installed and prints a poppler-utils install hint if not
  • Writes JPEGs beside the PDF using the PDF basename as the output prefix
  • Accepts optional first and last page arguments

scripts/zip_jpgs.sh

  • Finds matching basename-*.jpg files for the PDF
  • Creates a zip archive containing those JPGs
  • Uses ${base}-jpgs.zip by default when no output path is supplied

Notes

  • Output files follow the pdftoppm naming convention, typically basename-1.jpg, basename-2.jpg, etc.
  • If you need different image quality, output naming, or archive behavior, edit the bundled scripts rather than reimplementing the command inline.