Skip to main content

pdf2imgCrop

一个用于裁剪 PDF 页面内容并输出为图片或 PDF 的 Python 工具。

如果想从pptx转换为高清图片,可以先试用Adobe Acrobat的ppt插件。注意需要在插件的首选项->高级设置->图像中将分辨率调高到300dpi以上。(我自己用的dpi是2400)

功能特点

  • 将PDF文件输出为JPG、PNG、WebP、AVIF或TIF格式的图片
  • 支持直接裁剪并输出PDF文件
  • 自动裁剪图片周围的空白边距
  • 支持自定义DPI设置
  • 支持自动或手动控制 WebP 压缩方式
  • 支持自定义 JPG 质量、WebP 有损质量和 TIFF 压缩方式
  • 命令行界面,使用简单

安装

pip install pdf2imgCrop

使用方法

命令行使用

基本用法:

pdf2imgcrop your_file.pdf

指定DPI和输出格式:

pdf2imgcrop your_file.pdf -d 600 -f png

pdf2imgcrop your_file.pdf -d 600 -f pdf

pdf2imgcrop your_file.pdf -f tif --tif-compression lzw

pdf2imgcrop your_file.pdf -f jpg --jpg-quality 85

pdf2imgcrop your_file.pdf -f webp --webp-compression auto

pdf2imgcrop your_file.pdf -f webp --webp-compression lossy --webp-quality 75

查看帮助:

pdf2imgcrop --help

参数说明

  • file: PDF文件路径(必需)
  • -d, --dpi: 输出图片的DPI(默认:300)
  • -f, --format: 输出格式,可选 jpg、png、webp、avif、tif 或 pdf(默认:jpg)
  • -v, --version: 输出当前版本号并退出
  • --jpg-quality: JPG 输出质量,范围 0-100(默认:95)
  • --webp-compression: WebP 压缩方式,可选 auto、lossy 或 lossless(默认:auto)
  • --webp-quality: WebP 有损压缩质量,范围 0-100(默认:80)
  • --tif-compression: TIFF 压缩方式,可选 none、lzw 或 jpeg(默认:lzw)

代码示例

from pdf2imgCrop.core import convert_pdf

# 基本用法
convert_pdf("your_file.pdf")

# 自定义DPI和格式
convert_pdf("your_file.pdf", dpi=600, file_format="png")

# 自定义 JPG 质量
convert_pdf("your_file.pdf", file_format="jpg", jpg_quality=85)

# WebP 自动选择有损或无损压缩
convert_pdf("your_file.pdf", file_format="webp", webp_compression="auto")

# 手动指定 WebP 有损压缩质量
convert_pdf("your_file.pdf", file_format="webp", webp_compression="lossy", webp_quality=75)

# 以 LZW 压缩输出 TIFF
convert_pdf("your_file.pdf", file_format="tif", tif_compression="lzw")

# 直接裁剪并输出 PDF
convert_pdf("your_file.pdf", dpi=600, file_format="pdf")

输出

输出文件将保存在与输入PDF文件同名的目录中,后缀为"output"。例如,如果输入文件是"document.pdf",输出目录将是"documentoutput"。当输出格式为图片时,会按页生成图片文件;当输出格式为 pdf 时,会生成一个裁剪后的 PDF 文件。

Release files for pdf2imgCrop 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pdf2imgCrop 0.2.2
File Size Uploaded
pdf2imgcrop-0.2.2.tar.gz 39.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pdf2imgCrop 0.2.2
File Interpreter ABI Platform
pdf2imgcrop-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 46.9 kB

Release files / pdf2imgcrop-0.2.2.tar.gz

Download URL pdf2imgcrop-0.2.2.tar.gz
Size 39.0 kB
Tags Source
SHA-256 checksum
How to use checksums
14c54c7de0dc6ba4954aff5fc72a4395f614c1314c2bd08fcd7c71da0498d56a
BLAKE2b-256 checksum
How to use checksums
7fd100f196e408a97c8254351a6a423168864d6f72654e57fc2258a1ee00390b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / pdf2imgcrop-0.2.2-py3-none-any.whl

Download URL pdf2imgcrop-0.2.2-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ef91abb034733e4fe5d099590a38353a371df2d9d30a4c0b369ff0164d24e809
BLAKE2b-256 checksum
How to use checksums
4e38f6ef50eb45b3525c6010f7213a5a4f2faf00d15111765475dcc937b76302
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page