python pptx导出img(png,jpeg) [英] python pptx export img (png, jpeg)
本文介绍了python pptx导出img(png,jpeg)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经用Python开发了一个小的代码来生成PPTX.但我也想在这张幻灯片的png或jpeg中生成图片.
I have developed a small code in Python in order to generate PPTX. But I would like also to generate a picture in png or jpeg of this slide.
from pptx import Presentation
from pptx.util import Inches
img_path = 'monty-truth.png'
prs = Presentation()
blank_slide_layout = prs.slide_layouts[6]
slide = prs.slides.add_slide(blank_slide_layout)
left = top = Inches(1)
pic = slide.shapes.add_picture(img_path, left, top)
left = Inches(5)
height = Inches(5.5)
pic = slide.shapes.add_picture(img_path, left, top, height=height)
prs.save('test.pptx')
是否可以将PPTX文件(仅包括一张幻灯片)转换为PNG或JPEG图片?
Is there a way to transform a PPTX file (including just one slide) into a PNG or JPEG picture ?
推荐答案
您可以使用以下代码:
Application = win32com.client.Dispatch("PowerPoint.Application")
Presentation = Application.Presentations.Open(r"your_path")
Presentation.Slides[0].Export(r"the_new_path-file.jpg", "JPG")
Application.Quit()
Presentation = None
Application = None
在此行中,您可以更改要导出的幻灯片的编号(例如,下面的幻灯片编号为6):
With this line, you can change the number of the slide you want to export (for example below, for slide number 6) :
Presentation.Slides[5].Export(r"the_new_path-file.jpg", "JPG")
这篇关于python pptx导出img(png,jpeg)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文