png转pdf

读取“最终”的目录下的png转换到“最终_pdf”目录下的pdf文件

import os
import img2pdf
# 读取“最终”的目录下的png转换到“最终_pdf”目录下的pdf文件
def png_to_pdf(file,pdf_name):
	# 创建一个PDF文件 并以二进制方式写入
	with open(pdf_name, "wb") as f:
		# convert函数 用来转PDF
		write_content = img2pdf.convert(file)
		f.write(write_content) # 写入文件

directory = "./最终/"
# for root, dirs, files in os.walk(directory):
#     for file in files:
# 		filelll = os.path.join(root, file)
#     	# print(file)
#     	pdf_name = filelll+file.replace(".png",".pdf")
#     	png_to_pdf(file,pdf_name)

for root, dirs, files in os.walk(directory):
    for file in files:
        # if ("工程材料、构配件、设备报审表" in file) and (".docx" in file):
        filelll = os.path.join(root, file)
        print(filelll)
        pdf_name = filelll.replace("png","pdf")
        pdf_name = pdf_name.replace("最终","最终_pdf")
        print(pdf_name)
        png_to_pdf(filelll,pdf_name)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值