這篇文章主要介紹“python 如何提取PPT中所有文字的方法”,在日常操作中,相信很多人在python 如何提取PPT中所有文字的方法問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”python 如何提取PPT中所有文字的方法”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!

我就廢話不多說了,大家還是直接看代碼吧~
# 導入pptx包 from pptx import Presentation prs = Presentation(path_to_presentation) text_runs = [] for slide in prs.slides: for shape in slide.shapes: if not shape.has_text_frame: continue for paragraph in shape.text_frame.paragraphs: for run in paragraph.runs: text_runs.append(run.text)
補充:使用 python-pptx-interface 將PPT轉換成圖片
最簡單的方法就是使用PPTX的File中的SaveAs命令,將PPTX文件另存為JPEG格式。

▲ 使用PPT的SaveAs將PPTX存儲為JPEG
注意,在最后一步的時候需要選擇“所有幻燈片(A)”。

▲ 選擇所有幻燈片
最后,PPTX的每張幻燈片都以獨立文件方式保存到文件中。X
這部分的內容可以參照: How to Export PowerPoint Slides as JPG or Other Image Formats 中的介紹。
python-pptx是用于創建和更新PointPoint(PPTX)文件的Python庫。
一種常用的場合就是從數據庫內容生成一個客戶定制的PointPoint文件,這個過程通過點擊WEB應用上的連接完成。許多開發之 通過他們日常管理系統生成工程狀態匯報PPT。它也可以用于批量生成PPT或者產品特性說明PPT。
python-ppt License:
The MIT License (MIT) Copyright © 2013 Steve Canny, https://github.com/scanny
Python-PPTX對應的官方網絡網址:Python-PPTX https://python-pptx.readthedocs.io/en/latest/user/intro.html#
使用pip進行安裝:
pip install python-pptx
對于python要求: Python2.7,3.3,3.4,3.6
依賴庫:
Python 2.6, 2.7, 3.3, 3.4, or 3.6 lxml Pillow XlsxWriter (to use charting features)
下面的例子來自于: Get Start 。
from pptx import Presentation
prs = Presentation()
title_slide_layout = prs.slide_layouts[0]
slide = prs.slides.add_slide(title_slide_layout)
title = slide.shapes.title
subtitle = slide.placeholders[1]
title.text = 'Hello world!'
subtitle.text = 'python-pptx was here.'
prs.save(r'd:\temp\test.pptx')
printf("\a")
from pptx import Presentation from pptx.util import Inches, Pt prs = Presentation() blank_slide_layout = prs.slide_layouts[6] slide = prs.slides.add_slide(blank_slide_layout) left = top = width = height = Inches(1) txBox = slide.shapes.add_textbox(left, top, width, height) tf = txBox.text_frame tf.text = "This is text inside a textbox" p = tf.add_paragraph() p.text = "This is a second paragraph that's bold" p.font.bold = True p = tf.add_paragraph() p.text = "This is a third paragraph that's big" p.font.size = Pt(40) prs.save(r'd:\temp\test1.pptx')

pip install python-pptx-interface
注意:轉換生成的目錄必須使用新的目錄。否則就會出現:
Folder d:\temp\pptimage already exists. Set overwrite_folder=True, if you want to overwrite folder content.
from pptx_tools import utils pptfile = r'D:\Temp\如何搭建自己的電子實驗室_20210102R10.pptx' png_folder = r'd:\temp\pptimage' utils.save_pptx_as_png(png_folder, pptfile, overwrite_folder=True)
生成后的PPT對應的PNGImage。

▲ 生成后的PPTX對應的PNG圖片
將PPTX轉換成圖片,可以便于后期將文件上載到CSDN,或者用于DOP文件的制作。
到此,關于“python 如何提取PPT中所有文字的方法”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注創新互聯網站,小編會繼續努力為大家帶來更多實用的文章!
分享文章:python如何提取PPT中所有文字的方法-創新互聯
網站路徑:http://www.yijiale78.com/article0/phhoo.html
成都網站建設公司_創新互聯,為您提供網站制作、虛擬主機、網頁設計公司、網站排名、小程序開發、自適應網站
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯