标签:get ges 安装 you range file end blank path
主要用到
pip install python-pptx
用法:python pdf_to_pptx.py test.pdf
pdf_to_pptx.py:
# encoding: UTF-8
# pip install python-pptx
# https://python-pptx.readthedocs.io/
# need pdftk, pdftoppm installed
import sys
import os
import re
from pptx import Presentation
from pptx.util import Inches
from pptx.parts.image import Image
pdf_name = sys.argv[1]
os.system(‘mkdir -p png_tmps‘)
# dump pdf meta-data to get number of pages
os.system(‘pdftk {} dump_data_utf8 output data.txt‘.format(pdf_name))
data_content = open(‘data.txt‘).read()
groups = re.findall(‘NumberOfPages: (\d+)‘, data_content)
page_num = int(groups[0])
print(‘#pages:‘, page_num)
prs = Presentation()
prs_width = prs.slide_width
blank_slide_layout = prs.slide_layouts[6]
for i in range(page_num):
os.system(‘pdftoppm {} png_tmps/{} -png -f {} -singlefile -r 500‘.format(pdf_name, i+1, i+1))
img_path = ‘png_tmps/{}.png‘.format(i+1)
img = Image.from_file(img_path)
print(i+1)
slide = prs.slides.add_slide(blank_slide_layout)
left = top = Inches(0)
pic = slide.shapes.add_picture(img_path, left, top, width=prs_width)
prs.save(‘test.pptx‘)
2020.5.10 晚22:13
标签:get ges 安装 you range file end blank path
原文地址:https://www.cnblogs.com/maxuewei2/p/12865447.html