最近在整理每周的工作记录。因为每周的工作记录大都是单独的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文件的更多相关文章

  1. 转换Word文档为PDF文件

    1.使用 Office COM组件的Microsoft.Office.Interop.word.dll库 该方法需要在电脑上安装Office软件,并且需要Office支持转换为PDF格式,如果不支持, ...

  2. 微信公众号怎么添加附件?比如word文档,pdf文件等

    微信公众号怎么添加附件?比如word文档,pdf文件等   我们都知道创建一个微信公众号,在公众号中发布一些文章是非常简单的,但公众号添加附件下载的功能却被限制,如今可以使用小程序“微附件”进行在公众 ...

  3. JAVA使用aspose实现word文档转pdf文件

    引入jar包 下载地址:https://yvioo.lanzous.com/iezpdno3mob 然后打开下载的目录打开cmd执行 mvn install:install-file -Dfile=a ...

  4. Java 使用 jacob 将 word 文档转换为 pdf 文件

    网上查询了许许多多的博客,说利用 poi.iText.Jsoup.jdoctopdf.使用 jodconverter 来调用 openOffice 的服务来转换等等,我尝试了很多种,但要么显示不完全, ...

  5. 使用VBA将批量的WORD文档转换为PDF

    Sub BatchConvertToPDF() Dim destFolderPath As String destFolderPath = GetFolderPath If destFolderPat ...

  6. DEV word文档转换为pdf文件

    引用aspose.net控件2.0. docement doc=new document(文件路径和名称); doc.save(输出路径\file.pdf);

  7. 【好文翻译】一步一步教你使用Spire.Doc转换Word文档格式

    背景: 年11月,微软宣布作为ECMA国际主要合作伙伴,将其开发的基于XML的文件格式标准化,称之为"Office Open XML" .Open XML的引进使office文档结 ...

  8. word文档转pdf,支持.doc和.docx,另附抽取pdf指定页数的方法

    公司有个需求,需要将word转成pdf并且抽取首页用以展示,word文档有需要兼容.doc和.docx两种文档格式.其中.docx通过poi直接就可以将word转成pdf,.doc则无法这样实现,上网 ...

  9. 在linux中使用php将word文档转为pdf

    使用本教程需要在linux中安装openoffice,改页面中有详细的安装与使用教程(http://www.cnblogs.com/sustudy/p/3999628.html). 既然,你看了该教程 ...

随机推荐

  1. Java程序员的10道XML面试题

    包括web开发人员的Java面试在内的各种面试中,XML面试题在各种编程工作的面试中很常见.XML是一种成熟的技术,经常作为从一个平台到其他平台传输数据的标准.XML面试问题包括用于转换XML文件的X ...

  2. nyoj 845 无主之地1

    无主之地1 时间限制:1000 ms  |  内存限制:65535 KB 难度:0   描述 子晓最近在玩无主之地1,他对这个游戏的评价不错,结合了FPS与RPG元素,可玩度很高.不过,他发现了一代的 ...

  3. 利用.htacess 实现重定向

    步骤: 在网站目录下加入 .htaccess 文件中写 RewriteEngine On RewriteRule ^.*$ index.php 表示开启重写机制 重写到 index.php 的文件

  4. (转)java读取数据库表信息,子段

    import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sq ...

  5. mac不可或缺的套件管理器Homebrew

    Homebrew 1.简介 可以帮助我们快速安装软件, 如 brew install svn 快速卸载软件 , 如  brew uninstall svn 2.下载 打开终端, /usr/bin/ru ...

  6. Tomcat无法部署项目

    设置项目的Jdk,compire version 增加java EE 如果有必要,现在项目根目录下放置.mymetadata文件 <?xml version="1.0" en ...

  7. node.js在windows下的学习笔记(7)---express的app.js的详细配置说明

    var express = require('express'); var path = require('path'); var favicon = require('serve-favicon') ...

  8. 彻底解决android读取中文txt的乱码(自动判断文档类型并转码

    原文:http://blog.csdn.net/handsomedylan/article/details/6138400 public String convertCodeAndGetText(St ...

  9. [AngularJS] angular-schema-form -- 1

    Check out on gitHub, see the example on Demo page, see the document, extension. Mainly, there are th ...

  10. tar备份系统的方法

    下面是备份系统的方法: 然后打开终端,输入以下命令: 1.成为根用户:   sudo su 2.转到根目录:   cd / 然後,下面就是我用来备份我的系统的完整的命令:tar -cvpzf /med ...