
背景需求
委员让我打印2024年2025年4月的D刊杂志,A4彩打,单面。

有很多JPG,一个个JPG图片打开,实在太麻烦了。
我需要把多个jpg图片合并成成为一个PDF,按顺序排列打印。
deepseek写Python代码

代码展示
python
'''
D刊jpg图片合并PDF打印1
deepseek,阿夏
20250508
'''
import os
from reportlab.lib.pagesizes import A4
from reportlab.pdfgen import canvas
from reportlab.lib.utils import ImageReader
def images_to_pdf(folder_path, output_pdf):
c = canvas.Canvas(output_pdf, pagesize=A4)
width, height = A4
for filename in sorted(os.listdir(folder_path)):
if filename.lower().endswith(('.jpg', '.jpeg')):
image_path = os.path.join(folder_path, filename)
print(f"正在处理文件: {image_path}")
try:
img = ImageReader(image_path)
img_width, img_height = img.getSize()
ratio = min(width/img_width, height/img_height)
c.drawImage(img, 0, 0, width=img_width*ratio, height=img_height*ratio)
c.showPage()
except Exception as e:
print(f"无法处理文件 {filename}: {e}")
c.save()
print(f"PDF已成功创建为 {output_pdf}")
#
# 使用示例
folder = r"D:\\03D支部\\00D刊\\00 D刊ppt(2020.12截止)"
output = os.path.join(folder, "20250508D刊jpg合并.pdf")
images_to_pdf(folder, output)


但是放大后,我感觉图片有点模糊。

没有写出来。还是用前面一个模糊的pdf打印
使用阅读器

所有jpg都有(2021-2025年)我想挑选2024年-2025年的部分(从49页开始)

打印效果还可以,没有太模糊

