Skip to main content

将PDF文件转换为图片并自动裁剪空白边距

Project description

pdf2imgCrop

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

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

功能特点

  • 将PDF文件输出为JPG、PNG、WebP、AVIF或TIF格式的图片
  • 支持直接裁剪并输出PDF文件
  • 自动裁剪图片周围的空白边距
  • 支持自定义DPI设置
  • 支持自定义 JPG 质量和 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 --help

参数说明

  • file: PDF文件路径(必需)
  • -d, --dpi: 输出图片的DPI(默认:300)
  • -f, --format: 输出格式,可选 jpgpngwebpaviftifpdf(默认:jpg
  • --jpg-quality: JPG 输出质量,范围 0-100(默认:95
  • --tif-compression: TIFF 压缩方式,可选 nonelzwjpeg(默认: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)

# 以 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 文件。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pdf2imgcrop-0.2.0.tar.gz (37.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pdf2imgcrop-0.2.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file pdf2imgcrop-0.2.0.tar.gz.

File metadata

  • Download URL: pdf2imgcrop-0.2.0.tar.gz
  • Upload date:
  • Size: 37.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for pdf2imgcrop-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3fbebe3772a2024ad7cf6f398bec7740cb945a0b4b7d6bf08cdcc16c445187c0
MD5 3c53e5ce349bece32885abf9c5690001
BLAKE2b-256 4598dd6f987b425948d99b324d723caa675e559ef6eef6eeef5a8f7f351b52cd

See more details on using hashes here.

File details

Details for the file pdf2imgcrop-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pdf2imgcrop-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for pdf2imgcrop-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f32325bfbf60cc830a254fa27bba6a3dcb00110c9241808808ab51eb9646189a
MD5 aeb9bc7707109fe1f8fcbe622ea37644
BLAKE2b-256 8562f981cc25ca4f9d7ede615e5b9f06cf39a219b49618b63cf636832fa48872

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page