【办公类-99-05】20250508 D刊物JPG合并PDF便于打印

背景需求

委员让我打印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页开始)

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

感悟:

最近我把一些办公中的需求(EXCEL合并pdf、jpg合并PDF,word合并PDF、PPT的GIF动画),用deepseek快速写Python代码,进行运用,提高了效率。

未来AI工具会像office、WPS一样成为不可或缺的办公应用软件。

相关推荐
默_笙9 小时前
🍙 给每个请求过安检:FastAPI 是怎么把校验写进类型注解的
python
qq_426003969 小时前
启动playwright录制codegen生成自动化测试脚本
python·自动化
虎头金猫9 小时前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
长沙三为智能科技9 小时前
家政小程序开发从0到上线:五阶段交付流程与验收清单
python
伞伞悦读10 小时前
【第38期】Python 模块与包详解:import、from、模块搜索路径、包结构和 __init__
开发语言·python
只睡四小时10 小时前
Canvas 弹道联机实战:700 行 + 固定时间步长
python·websocket·html5·游戏开发·canvas
奇思妙想聪明勤奋的小羊11 小时前
DeepAgents第5章:子Agent 与上下文隔离—让 Agent学会委派
人工智能·python·学习·语言模型
lpfasd12311 小时前
2026年第38周GitHub趋势周报
python·科技·github
IZero0711 小时前
Jev 与 Laya
python·语言模型