【办公类-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一样成为不可或缺的办公应用软件。

相关推荐
花酒锄作田8 小时前
使用 pkgutil 实现动态插件系统
python
前端付豪12 小时前
LangChain链 写一篇完美推文?用SequencialChain链接不同的组件
人工智能·python·langchain
曲幽13 小时前
FastAPI实战:打造本地文生图接口,ollama+diffusers让AI绘画更听话
python·fastapi·web·cors·diffusers·lcm·ollama·dreamshaper8·txt2img
老赵全栈实战13 小时前
Pydantic配置管理最佳实践(一)
python
阿尔的代码屋19 小时前
[大模型实战 07] 基于 LlamaIndex ReAct 框架手搓全自动博客监控 Agent
人工智能·python
AI探索者2 天前
LangGraph StateGraph 实战:状态机聊天机器人构建指南
python
AI探索者2 天前
LangGraph 入门:构建带记忆功能的天气查询 Agent
python
FishCoderh2 天前
Python自动化办公实战:批量重命名文件,告别手动操作
python
躺平大鹅2 天前
Python函数入门详解(定义+调用+参数)
python
曲幽2 天前
我用FastAPI接ollama大模型,差点被asyncio整崩溃(附对话窗口实战)
python·fastapi·web·async·httpx·asyncio·ollama