批量转换word文档到pdf文件
最近在整理每周的工作记录。因为每周的工作记录大都是单独的word文件,有时候忘记了也不容易找出来,一个个打开查找太费劲,因此想着把这些文件通过word2016的另存为功能转换为pdf,然后永Acrobat合并起来。
思路如下:
(1)通过Python代码搜索指定输入目录下的所有word文档,调用word COM接口,将文件转存为pdf文件到指定输出目录;
(2)利用Acrobat将输出的目录中所有的pdf合并成单个pdf文件供存档查阅。
步骤(1)的代码如下:
import os
#import comtypes.client
import win32com.client
import time wdFormatPDF = 17 # absolute path is needed
# be careful about the slash '\', use '\\' or '/' or raw string r"..."
in_dir=u'input directory'
out_dir=u'output directory' word = win32com.client.Dispatch('Word.Application')
word.Visible = True
time.sleep(3)
first_flag=True try:
for root, dirs, files in os.walk(in_dir):
for file in files:
if (file.endswith(".docx") or file.endswith(".doc")) and (not file.startswith('~')):
in_file=os.path.join(root, file)
out_file_temp=os.path.join(out_dir,file)
out_file=out_file_temp.rsplit('.',1)[0]+u'.pdf'
# print(in_file)
# print(out_file)
# skip existed files
if os.path.isfile(out_file):
continue
print "================================================"
print "convert\n'"+in_file+"' into\n"+ out_file +"'\n"
doc=word.Documents.Open(in_file)
doc.SaveAs(out_file, FileFormat=wdFormatPDF)
doc.Close()
if first_flag:
word.Visible = False
first_flag = False
except Exception as inst:
print(type(inst)) # the exception instance
print(inst.args) # arguments stored in .args
print(inst) # __str__ allows args to be printed directly, word.Quit()
print "Coversion Done."
步骤(2):


可以看到每个文件的名字都变成了书签,方便查阅。
参考:
http://stackoverflow.com/questions/6011115/doc-to-pdf-using-python
批量转换word文档到pdf文件的更多相关文章
- 转换Word文档为PDF文件
1.使用 Office COM组件的Microsoft.Office.Interop.word.dll库 该方法需要在电脑上安装Office软件,并且需要Office支持转换为PDF格式,如果不支持, ...
- 微信公众号怎么添加附件?比如word文档,pdf文件等
微信公众号怎么添加附件?比如word文档,pdf文件等 我们都知道创建一个微信公众号,在公众号中发布一些文章是非常简单的,但公众号添加附件下载的功能却被限制,如今可以使用小程序“微附件”进行在公众 ...
- JAVA使用aspose实现word文档转pdf文件
引入jar包 下载地址:https://yvioo.lanzous.com/iezpdno3mob 然后打开下载的目录打开cmd执行 mvn install:install-file -Dfile=a ...
- Java 使用 jacob 将 word 文档转换为 pdf 文件
网上查询了许许多多的博客,说利用 poi.iText.Jsoup.jdoctopdf.使用 jodconverter 来调用 openOffice 的服务来转换等等,我尝试了很多种,但要么显示不完全, ...
- 使用VBA将批量的WORD文档转换为PDF
Sub BatchConvertToPDF() Dim destFolderPath As String destFolderPath = GetFolderPath If destFolderPat ...
- DEV word文档转换为pdf文件
引用aspose.net控件2.0. docement doc=new document(文件路径和名称); doc.save(输出路径\file.pdf);
- 【好文翻译】一步一步教你使用Spire.Doc转换Word文档格式
背景: 年11月,微软宣布作为ECMA国际主要合作伙伴,将其开发的基于XML的文件格式标准化,称之为"Office Open XML" .Open XML的引进使office文档结 ...
- word文档转pdf,支持.doc和.docx,另附抽取pdf指定页数的方法
公司有个需求,需要将word转成pdf并且抽取首页用以展示,word文档有需要兼容.doc和.docx两种文档格式.其中.docx通过poi直接就可以将word转成pdf,.doc则无法这样实现,上网 ...
- 在linux中使用php将word文档转为pdf
使用本教程需要在linux中安装openoffice,改页面中有详细的安装与使用教程(http://www.cnblogs.com/sustudy/p/3999628.html). 既然,你看了该教程 ...
随机推荐
- 【组队训练】2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest
好多oj都崩掉了,于是打了cf.. 开始开的最后一题...尼玛题好长终于看完了...神题不会.... I过了好多人..看了下,一眼题...随便敲了下,1A ]; int main(){ int n, ...
- Visual Studio 2008 – ASP.NET “System.Runtime.InteropServices.COMException”
The Issue When openning an existing ASP.NET project for the first time in Visual Studio 2008 it retu ...
- Android实例-设置消息提醒(XE8+小米2)
相关资料: 1.官网实例:http://docwiki.embarcadero.com/RADStudio/XE5/en/Mobile_Tutorial:_Using_the_Notification ...
- Android实例-TTabControl的使用(XE8+小米2)
结果: 1.如果直接改变Tab的TabIndex,那样是没有动态效果的.如果想要动态效果需要用到ChangeTabAction1; 2.ChangeTabAction1可以直接为按钮指定Action ...
- A Tour of Go Exercise: Slices
Implement Pic. It should return a slice of length dy, each element of which is a slice of dx 8-bit u ...
- SaltStack管理从这里开始
Modules 1:查看所有module列表: salt 'jcfx-4' sys.list_modules jcfx-4: - acl - aliases - alternatives - apac ...
- sql STUFF用法
sql STUFF用法 1.作用 删除指定长度的字符,并在指定的起点处插入另一组字符. 2.语法 STUFF ( character_expression , start , length ,char ...
- JavaScript要点(七) 函数调用
JavaScript 函数有 4 种调用方式. 每种方式的不同方式在于 this 的初始化. this 关键字 注意: this 是保留关键字,你不能修改 this 的值. ⚠️一般而言,在Java ...
- jQuery生成二维条形码 jquery.qrcode.js
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...
- UITableViewCell 高度自适应
UITableViewCell 高度自适应一直是我们做动态Cell高度时遇到的最烦躁的问题,Cell动态高度计算可以去看看sunny的这篇文章介绍,今天主要和大家分享下我在使用systemLayout ...