python实现pdf转pptx
ppt_path = r"C:\Users\32717\Documents\WeChat Files\wxid_o66fzv6tiktx22\FileStorage\File\2025-03\学子心志愿行.pptx"pdf_path = r"C:\Users\32717\Documents\WeChat Files\wxid_o66fzv6tiktx22\FileStorage\File\2025
·
# -- coding: utf-8 --
from pdf2image import convert_from_path
from pptx import Presentation
from pptx.util import Inches
def pdf_to_ppt(pdf_path, ppt_path):
# 打开 PDF 文件并将其转换为图像列表
images = convert_from_path(pdf_path)
# 创建一个新的 PPT 演示文稿
prs = Presentation()
# 遍历每个图像
for image in images:
# 创建一个空白幻灯片
slide = prs.slides.add_slide(prs.slide_layouts[6])
# 保存图像到临时文件
image_path = "temp_image.jpg"
image.save(image_path, 'JPEG')
# 获取幻灯片的宽度和高度
slide_width = prs.slide_width
slide_height = prs.slide_height
# 插入图像到幻灯片中,并调整大小以适应幻灯片
pic = slide.shapes.add_picture(image_path, 0, 0, width=slide_width, height=slide_height)
# 保存 PPT 文件
prs.save(ppt_path)
print(f"PDF 文件 {pdf_path} 已成功转换为 PPT 文件 {ppt_path}")
# 调用函数进行转换
pdf_path = r"C:\Users\32717\Documents\WeChat Files\wxid_o66fzv6tiktx22\FileStorage\File\2025-03\学子心志愿行.pdf"
ppt_path = r"C:\Users\32717\Documents\WeChat Files\wxid_o66fzv6tiktx22\FileStorage\File\2025-03\学子心志愿行.pptx"
pdf_to_ppt(pdf_path, ppt_path)更多推荐
所有评论(0)