您好,登錄后才能下訂單哦!
這篇文章主要介紹“python 如何提取PPT中所有文字的方法”,在日常操作中,相信很多人在python 如何提取PPT中所有文字的方法問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”python 如何提取PPT中所有文字的方法”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!
我就廢話(huà)不多說(shuō)了,大家還是直接看代碼吧~
# 導(dǎo)入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)
補(bǔ)充:使用 python-pptx-interface 將PPT轉(zhuǎn)換成圖片
最簡(jiǎn)單的方法就是使用PPTX的File中的SaveAs命令,將PPTX文件另存為JPEG格式。
▲ 使用PPT的SaveAs將PPTX存儲(chǔ)為JPEG
注意,在最后一步的時(shí)候需要選擇“所有幻燈片(A)”。
▲ 選擇所有幻燈片
最后,PPTX的每張幻燈片都以獨(dú)立文件方式保存到文件中。X
這部分的內(nèi)容可以參照: How to Export PowerPoint Slides as JPG or Other Image Formats 中的介紹。
python-pptx是用于創(chuàng)建和更新PointPoint(PPTX)文件的Python庫(kù)。
一種常用的場(chǎng)合就是從數(shù)據(jù)庫(kù)內(nèi)容生成一個(gè)客戶(hù)定制的PointPoint文件,這個(gè)過(guò)程通過(guò)點(diǎn)擊WEB應(yīng)用上的連接完成。許多開(kāi)發(fā)之 通過(guò)他們?nèi)粘9芾硐到y(tǒng)生成工程狀態(tài)匯報(bào)PPT。它也可以用于批量生成PPT或者產(chǎn)品特性說(shuō)明PPT。
python-ppt License:
The MIT License (MIT) Copyright © 2013 Steve Canny, https://github.com/scanny
Python-PPTX對(duì)應(yīng)的官方網(wǎng)絡(luò)網(wǎng)址: Python-PPTX https://python-pptx.readthedocs.io/en/latest/user/intro.html#
使用pip進(jìn)行安裝:
pip install python-pptx
對(duì)于python要求: Python2.7,3.3,3.4,3.6
依賴(lài)庫(kù):
Python 2.6, 2.7, 3.3, 3.4, or 3.6 lxml Pillow XlsxWriter (to use charting features)
下面的例子來(lái)自于: 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
注意:轉(zhuǎn)換生成的目錄必須使用新的目錄。否則就會(huì)出現(xiàn):
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\如何搭建自己的電子實(shí)驗(yàn)室_20210102R10.pptx' png_folder = r'd:\temp\pptimage' utils.save_pptx_as_png(png_folder, pptfile, overwrite_folder=True)
生成后的PPT對(duì)應(yīng)的PNGImage。
▲ 生成后的PPTX對(duì)應(yīng)的PNG圖片
將PPTX轉(zhuǎn)換成圖片,可以便于后期將文件上載到CSDN,或者用于DOP文件的制作。
到此,關(guān)于“python 如何提取PPT中所有文字的方法”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注億速云網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。