[Python Study Notes]批量将ppt转换为pdf v1.0
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
>>文件: ppt2pdf.py
>>作者: liu yang
>>邮箱: liuyang0001@outlook.com
>>博客: www.cnblogs.com/liu66blog ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' #!/usr/bin/env python
# -*- coding: utf-8 -*- import sys, os
# 调用com组件包
import comtypes.client # 第一步:得到ptr
def init_powerpoint():
powerpoint = comtypes.client.CreateObject("Powerpoint.Application")
powerpoint.Visible = 1
return powerpoint # 第二步:找到该路径下的所有ppt(x)文件,并将其路径添加到cwd
def convert_files_in_folder(powerpoint, folder):
# 将当前所有文件及文件夹添加进列表
files = os.listdir(folder)
print('files:',files)
# 将所有以.ppt(x)结尾的文件加入cwd path
pptfiles = [f for f in files if f.endswith((".ppt", ".pptx"))]
for pptfile in pptfiles:
# 加入判断,如果当前转换成的pdf已存在,就跳过不添加
print(pptfile)
if pptfile+'.pdf' in files :
break
# 加入cwd环境
fullpath = os.path.join(cwd, pptfile)
ppt_to_pdf(powerpoint, fullpath, fullpath) #第三步:将cwd路径下转换成pdf格式
def ppt_to_pdf(powerpoint, inputFileName, outputFileName, formatType = 32):
# 切片取后缀是否为pdf
if outputFileName[-3:] != 'pdf':
outputFileName = outputFileName + ".pdf"
# 调用接口进行转换
deck = powerpoint.Presentations.Open(inputFileName)
deck.SaveAs(outputFileName, formatType) # formatType = 32 for ppt to pdf
deck.Close() if __name__ == "__main__":
# 得到PowerPoint应用的ptr
powerpoint = init_powerpoint()
# print(powerpoint)
# 得到当前路径
cwd = os.getcwd()
# 打印当前路径
print(cwd)
# 调用powerpoit进行转换cwd path下的ppt(x)格式
convert_files_in_folder(powerpoint, cwd)
# 转换结束后关闭
powerpoint.Quit() # 感谢github的原作者
# 该脚本源于https://github.com/jackbrookes/batch-ppt-to-pdf/blob/master/batch_ppt_to_pdf.py
[Python Study Notes]批量将ppt转换为pdf v1.0的更多相关文章
- [Python Study Notes]批量将wold转换为pdf
本文代码,由原ppt2pdf.py进行改写 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...
- Java使用Openoffice将word、ppt转换为PDF
最近项目中要实现WORD的文件预览功能,我们可以通过将WORD转换成PDF或者HTML,然后通过浏览器预览. OpenOffice OpenOffice.org 是一套跨平台的办公室软件套件,能在 W ...
- PHP 实现 word/excel/ppt 转换为 PDF
前段时间负责公司内部文件平台的设计,其中有一个需求是要能够在线浏览用户上传的 office 文件. 我的思路是先将 office 转换成 PDF,再通过 pdf.js 插件解析 PDF 文件,使其能在 ...
- 20171024xlVBA批量获取PPT\WORD\PDF页数
Public Sub ModifyFileNames() Dim FolderPath As String Dim FileNames As Variant Dim dotPos As Long Di ...
- Python爬虫实战:将网页转换为pdf电子书
写爬虫似乎没有比用 Python 更合适了,Python 社区提供的爬虫工具多得让你眼花缭乱,各种拿来就可以直接用的 library 分分钟就可以写出一个爬虫出来,今天就琢磨着写一个爬虫,将廖雪峰的 ...
- [Python Study Notes]物体运动检测
基于opencv的cv2模块实现 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...
- word、ppt转换为pdf
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- [Python Study Notes]匿名函数
Python 使用 lambda 来创建匿名函数. lambda这个名称来自于LISP,而LISP则是从lambda calculus(一种符号逻辑形式)取这个名称的.在Python中,lambda作 ...
- [Python Study Notes]字符串处理技巧(持续更新)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...
随机推荐
- 分享整理的免费API接口
天气接口 聚合数据: http://op.juhe.cn/onebox/weather/query 用例 官方文档 来源:weather.com 百度接口: http://api.map.baidu. ...
- MySQL字符集设置—MySQL数据库乱码问题
MySQL(4.1以后版本) 服务器中有六个关键位置使用了字符集的概念,他们是:client .connection.database.results.server .system.MySQL有两个字 ...
- RequestParam\@ResponseBody
为什么不写 RequestParam 也能拿到参数 三种写法,test(String name), test(@RequestParam String name), test(@RequestPara ...
- git fetch, git pull 剖析
真正理解 git fetch, git pull 要讲清楚git fetch,git pull,必须要附加讲清楚git remote,git merge .远程repo, branch . commi ...
- 【转】高精度GPS测量中框架基准的统一
一.地面基准点的坐标基准转换 一般情况下,我们可以从IERS或IGS等机构获取最新的站坐标和速度场,这些站坐标和速度场是在某一特定基准框架和历元下的坐标值,若要提供高精度GPS网的分析使用,还需要作框 ...
- Date对象和正则对象
1.Date对象 创建 var date1 = new Date(); var date2 = new Date(12983798123);//填一个毫秒值,应该是距离1970年1月1日.....多少 ...
- 关于if和else嵌套—蛋疼
嵌套使用的时候else if和else遵循就近原则,和上面最靠近该语句的if语句匹配,要把else if看成是一个整体.就这么干,这样好理解一点. 一个if...else if...else语句中可以 ...
- TCP/IP参考模型
1.简介 什么是TCP/IP参考模型? TCP/IP模型是网络通信模型的一种.网络通信模型还包括OSI,旨在使各种计算机在世界范围内互连为网络.其中有OSI为七层模型.TCP/IP为四层模型,现在大部 ...
- python之在线平台与量化投资
0. 第一个量化策略 # 初始化函数,设定基准等等 def initialize(context): set_benchmark('000300.XSHG') g.security = get_ind ...
- Hello 2018
愈发觉得写技术博客对于自己写作能力的提升会很有帮助,于是在今天终于用Github+Jekyll的方式搭建了自己的博客,从今往后就在这里记录自己在技术上成长的点滴,希望自己的总结和思考也能帮助到其他人. ...