使用python调用wps v9转换office文件到pdf
#!/usr/bin/python2.6
# -*- coding: utf-8 -*-
# pip install timeout-decorator import os
import win32com.client # wps使用的是wps2016版本
# 转换 Word文件档到pdf
def ConvertDocToPdf(src, dst):
if not os.path.exists(src):
print(src + "不存在,无法继续!")
return False
os.system('taskkill /im wps.exe')
# 如果文件存在就删除
if os.path.exists(dst):
os.remove(dst)
o = win32com.client.Dispatch("Kwps.Application")
o.Visible = False
doc = o.Documents.Open(src);
doc.ExportAsFixedFormat(dst, 17)
o.Quit();
if os.path.exists(dst):
return True
else:
return False # 转换 Ppt文件档到pdf
def ConvertPptToPdf(src, dst):
if not os.path.exists(src):
print(src + "不存在,无法继续!")
return False
os.system('taskkill /im wps.exe')
# 如果文件存在就删除
if os.path.exists(dst):
os.remove(dst)
wpp = win32com.client.Dispatch("Kwpp.Application")
# o.Visible=False
ppt = wpp.Presentations.Open(src)
ppt.SaveAs(dst, 32)
ppt.Close()
wpp.Quit()
if os.path.exists(dst):
return True
else:
return False # 转换 xls文件档到pdf
def ConvertXlsToPdf(src, dst):
if not os.path.exists(src):
print(src + "不存在,无法继续!")
return False
os.system('taskkill /im wps.exe')
# 如果文件存在就删除
if os.path.exists(dst):
os.remove(dst)
xlApp = win32com.client.Dispatch("Ket.Application")
excel = xlApp.Workbooks.Open(src)
excel.ExportAsFixedFormat(0, dst)
excel.Close()
xlApp.Quit()
if os.path.exists(dst):
return True
else:
return False # 当前目录
d = os.path.dirname(__file__)
abspath = os.path.abspath(d)
#
#
# 测试用例
src = abspath + r"/Doc/test.doc"
dst = abspath + r"/Doc/test.doc.pdf"
r = ConvertDocToPdf(src, dst)
print(r) # 测试用例
src = abspath + r"/Doc/test.xlsx"
dst = abspath + r"/Doc/test.xlsx.pdf"
r = ConvertXlsToPdf(src, dst)
print(r) # 测试用例
src = abspath + r"/Doc/test.pptx"
dst = abspath + r"/Doc/test.pptx.pdf"
r = ConvertPptToPdf(src, dst)
print(r)
使用python调用wps v9转换office文件到pdf的更多相关文章
- openoffice启动服务并将office文件转换为pdf文件
1.首先下载最新版的openoffice工具,安装完成之后安装服务,, win+r打开命令提示符 输入cmd,cd C:\Program Files (x86)\OpenOffice 4\progra ...
- React中使用react-file-viewer,实现预览office文件(pdf,word,xlsx等文件)前端实现
最近做一个项目要求在前端浏览器可以直接打开office文件(pdf,doc,xlsx等文件).pdf浏览器可以直接打开(可以直接用a标签href="文件地址"或者iframe标签s ...
- 【Python】调用WPS V9 API,实现Word转PDF
WPS 的API,即COM,主要分为V8与V9两个版本,网上容易查到的例子,都是V8的. 现在官网上可以下载的,2013抢鲜版,就是V9的API. Python 调用COM 需要安装 Python f ...
- 【Python】调用WPS V9 API,实现PPT转PDF
WPS 的API,即COM,主要分为V8与V9两个版本,网上容易查到的例子,都是V8的. 现在官网上可以下载的,2013抢鲜版,就是V9的API. Python 调用COM 需要安装 Python f ...
- java调用com组件将office文件转换成pdf
在非常多企业级应用中都涉及到将office图片转换成pdf进行保存或者公布的场景,由于pdf格式的文档方便进行加密和权限控制(类似于百度文库).总结起来眼下将office文件转换 成pdf的方法主要有 ...
- java 调用OpenOffice将word格式文件转换为pdf格式
一:环境搭建 OpenOffice 下载地址http://www.openoffice.org/ JodConverter 下载地址http://sourceforge.net/projects/jo ...
- c#通过libreOffice实现 office文件转pdf文件
一.安装libreOffice 点击官网下载libreOffice 二.创建一个新的项目LibreOffice 创建一个新的项目,方便后面调用 添加下面代码 public class OfficeCo ...
- Java转换Word文件到PDF文件
使用Docx4j将Word文件转换为PDF文件: public static void convertDocxToPDF(String docxFilePath, String pdfPath) th ...
- 发送垃圾邮件的僵尸网络——药物(多)、赌博、股票债券等广告+钓鱼邮件、恶意下载链接、勒索软件+推广加密货币、垃圾股票、色情网站(带宏的office文件、pdf等附件)
卡巴斯基实验室<2017年Q2垃圾邮件与网络钓鱼分析报告> 米雪儿 2017-09-07 from:http://www.freebuf.com/articles/network/1465 ...
随机推荐
- Leetcode - 309. Best Time to Buy and Sell Stock with Cooldown
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- Libevent源码分析系列【转】
转自:https://www.cnblogs.com/zxiner/p/6919021.html 1.使用libevent库 源码那么多,该怎么分析从哪分析呢?一个好的方法就是先用起来,会用了 ...
- python3+selenium入门12-警告框处理
在WebDriver中要处理JS生成的alert.confirm以及prompt,需要使用到switch_to_alert()定位到alert/confirm/prompt,然后再使用text.acc ...
- vue路由vue-router的使用
对于单页应用,官方提供了vue-router进行路由跳转的处理. 安装 基于传统,我更喜欢采用npm包的形式进行安装. npm install vue-router --save 当然,官方采用了多种 ...
- Zookeeper-Watcher机制与异步调用原理
转载于:http://shift-alt-ctrl.iteye.com/blog/1847320 Watcher机制:目的是为ZK客户端操作提供一种类似于异步获得数据的操作. 1)在创建Zookeep ...
- 无备份mysql删除表后恢复
mysql从5.6.17开始自动设置innodb_file_per_table为on,每个表设置单独表空间,数据不是集中存放在ibdata1里.下面测试下无备份后drop表后的恢复. 前奏生成数据字典 ...
- php正则替换函数-----preg_replace ( mixed $pattern , mixed $replacement , mixed $subject [, int $limit = -1 [, int &$count ]] )
preg_replace — 执行一个正则表达式的搜索和替换 说明 mixed preg_replace ( mixed $pattern , mixed $replacement , mixed $ ...
- Laravel 5.2控制器--为什么命令行创建控制器的时候会报错?
今天我遇到过一种情况:就是之前创建的控制器名称想更改(仅仅只是大小写问题而已),然后用命令行重新创建新的名称的控制器. 结果就报错了? [ReflectionException] Class App\ ...
- 【原创】大数据基础之Marathon(2)marathon-lb
marathon-lb 官方:https://github.com/mesosphere/marathon-lb 一 简介 Marathon load balancer (Marathon-LB) i ...
- Oracle Package的全局变量与Session
Oracle Package的全局变量与Session2012-07-26 aaie_ 阅 3595 转 10简单讲,同一个session下pageckage中的全局变量时公共的,会导致冲突.以下是一 ...