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 INLINECODE3 - Install the
poppler-utils package before running the scripts
Install poppler-utils
CODEBLOCK0
- 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
- INLINECODE10
CODEBLOCK1
Standard workflow
- 1. Convert the PDF with INLINECODE11
- Bundle the output images with
scripts/zip_jpgs.sh if needed
CODEBLOCK2
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.
pdf2jpg
概述
使用 poppler-utils 中的 pdftoppm 将 PDF 转换为 JPEG 页面图像,然后可选择将生成的 JPG 文件打包为 zip 压缩包。
环境要求
- - pdftoppm 必须存在于 PATH 环境变量中
- 运行脚本前需安装 poppler-utils 软件包
安装 poppler-utils
bash
sudo apt update
sudo apt install -y poppler-utils
- 通过包管理器安装 Poppler,然后将 pdftoppm.exe 添加到 PATH 环境变量中
- 常用选项:
- winget install -e --id oschwartz10612.Poppler
- choco install poppler
- scoop install poppler
bash
brew install poppler
标准工作流程
- 1. 使用 scripts/pdf2jpg.sh 转换 PDF
- 如需打包,使用 scripts/zip_jpgs.sh 将输出图片打包
bash
./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/pdf2jpg.sh
- - 若未提供 PDF 路径,则提示用户输入
- 验证输入文件是否存在
- 验证 pdftoppm 是否已安装,若未安装则显示 poppler-utils 安装提示
- 使用 PDF 的基本文件名作为输出前缀,将 JPEG 文件写入 PDF 所在目录
- 支持可选的起始页和结束页参数
scripts/zip_jpgs.sh
- - 查找与 PDF 对应的 basename-*.jpg 文件
- 创建包含这些 JPG 文件的 zip 压缩包
- 未指定输出路径时,默认使用 ${base}-jpgs.zip 作为文件名
注意事项
- - 输出文件遵循 pdftoppm 的命名规则,通常为 basename-1.jpg、basename-2.jpg 等
- 如需调整图片质量、输出命名或归档行为,请直接修改附带的脚本,无需重新实现命令