承上一篇:java:pdfbox 3.0 去除扫描版PDF中文本水印
# 导出扫描版PDF文件中每页的图片文件
java -jar pdfbox-app-3.0.3.jar export:images -prefix=test -i your_book.pdf
导出
Writing image: test-1.jpg
Writing image: test-2.jpg
Writing image: test-3.png
……
在日常工作中,我们经常需要将多张图片合并成一个PDF文件,以便于分享或打印。Python作为一种强大的编程语言,提供了丰富的库和工具,使得这一任务变得非常简单。在本文中,我们将介绍如何使用Python合并多张图片并生成一个PDF文件的方法。我们需要安装两个库:Pillow 和ReportLab。Pillow 用于处理图片,ReportLab 用于生成PDF文件。
pip install Pillow
pip install reportlab
reportlab-4.2.2-py3-none-any.whl (1.9 MB)
编写 merge_pdf1.py 如下
# -*- coding: utf-8 -*-
""" reportLab 将多个图片合并成一个PDF文件 """
import os
from PIL import Image
from reportlab.pdfgen import canvas
images_dir = "." # imgs
tmpdir = r"\tmp" # Win 10
def revise(s):
""" 修正图片文件名中的数字,假设0<页数<=999 """
prefix = s[0:5]
d