python是一门很强大的语言,因为有着丰富的第三方库,所以可以说Python是无所不能的。
很多人都知道,Python可以操作Excel,PDF·还有PPT,这篇文章就围绕Python提取PPT中的文字来写,包括提取PPT中的艺术字,图片中的文字。
因为实现环境是linux,所以无法用win32com来实现这个需求,使用extract库也可以提取PDF,PPT等文件中的文字,但这里不用extract来实现,用python-pptx,如果熟悉extract库一点的也知道,extract中也使用了python-pptx,实现过程也是调用了python-pptx。
presentation = pptx.Presentation(fp)
results = []
for slide in presentation.slides:
for shape in slide.shapes:
if shape.has_text_frame:
for paragraph in shape.text_frame.paragraphs:
part = []
for run in paragraph.runs:
part.append(run.text)
results.append(''.join(part))
elif isinstance(shape, Picture):
content = self.parsepic.request_api(shape.image.blob)
results.append(''.join(con