批量转换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). 既然,你看了该教程 ...
随机推荐
- Android实例-打电话、发短信和邮件,取得手机IMEI号(XE8+小米2)
结果: 1.不提示发短信卡住,点击没有反映,我猜想,可能是因为我用的是小米手机吧. 2.接收短信报错,我猜想可能是我改了里面的方法吧(哪位大神了解,求指教). 3.project -->opti ...
- 【3D研发笔记】之【数学相关】(一):坐标系
现在开始学习3D基础相关的知识,本系列的数学相关笔记是基于阅读书籍<3D数学基础:图形与游戏开发>而来,实现代码使用AS3,项目地址是:https://github.com/hammerc ...
- 别名的应用(New-Alias)
New-Alias -name appcmd -value $env:windir\system32\inetsrv\appcmd.exe 这样就可以在当前PS环境下直接使用appcmd了
- 【ZT】修复iCloud中查找我的iPhone、查找我的iPad无法显示地图的方法
http://blog.sina.com.cn/s/blog_4ff28d30010118cm.html 进入C:\Windows\System32\drivers\etc在hosts文件里加入如下地 ...
- Jordan Lecture Note-6: The Solutions of Nonlinear Equation.
The Solutions of Nonlinear Equation 本文主要介绍几种用于解非线性方程$f(x)=0$的一些方法. (1) Bisection Method. 算法: step 1: ...
- 如何定位到div滚动条的最底端
function ScrollDiv() { var ex = document.getElementById("calm"); ex.scrollTop = ex.scrollH ...
- 20 Best Drag and Drop jQuery Plugins--reference
reference from:http://dizyne.net/20-best-drag-drop-jquery-plugins/ jQuery has done a great job repla ...
- Android Studio配置Dagger2 以及butterknife
一.配置butterknife 在build.gradle(Module)文件中的dependencies模块添加: dependencies { // add butterknife compile ...
- C# for AUTOCAD ActiveX获取图形对象坐标程序
C# for AUTOCAD ActiveX获取图形对象坐标程序 using System;using System.Collections.Generic;using System.Componen ...
- oracle的sql函数
只读事务set transaction read only当一个用户添加了只读事务,则查询时只会查到设置只读事务之前的内容,在并发量大的系统中,通过设置只读事务 便于统计 oracle的sql函数的使 ...