1.python实现word批量转pdf

2.c# 实现word批量转pdf

1.python实现word批量转pdf

# -*- coding: utf-8 -*-
"""
Spyder EditorThis is a temporary script file.
"""
import glob as gb
import sys
import imp
imp.reload(sys)
import sys, os
from win32com.client import Dispatch, constants, gencache
import tkinter as tk
from tkinter.filedialog import askdirectory#REPORT_DOC_PATH = 'C:/Users/dell/Desktop/新建文件夹'
#REPORT_PDF_PATH = 'C:/Users/dell/Desktop/新建文件夹'
root = tk.Tk()
root.withdraw()
REPORT_DOC_PATH = askdirectory()
REPORT_PDF_PATH = REPORT_DOC_PATHdef word2pdf(filename, doc):if doc == "Y":input = filename + '.doc'elif doc == "N":input = filename + '.docx'output = filename + '.pdf'pdf_name = outputos.chdir(REPORT_DOC_PATH)if not os.path.isfile(input):print (u'%s not exist' % input)return Falseif (not os.path.isabs(input)):input = os.path.abspath(input)else:print (u'%s not absolute path' % input)return Falseif (not os.path.isabs(output)):os.chdir(REPORT_PDF_PATH)output = os.path.abspath(output)else:print (u'%s not absolute path' % output)return Falsetry:print (input, output)gencache.EnsureModule('{00020905-0000-0000-C000-000000000046}', 0, 8, 4)w = Dispatch("Word.Application")try:doc = w.Documents.Open(input, ReadOnly=1)doc.ExportAsFixedFormat(output, constants.wdExportFormatPDF, \Item=constants.wdExportDocumentWithMarkup,CreateBookmarks=constants.wdExportCreateHeadingBookmarks)except:print (' exception')finally:w.Quit(constants.wdDoNotSaveChanges)if os.path.isfile(pdf_name):print ('translate success')return Trueelse:print ('translate fail')return Falseexcept:print (' exception')return -1if __name__ == '__main__':import osfor dirpath, dirnames, filenames in os.walk(REPORT_DOC_PATH):for file in filenames:fullpath = os.path.join(dirpath, file)print (fullpath, file)if 'docx' in file:rc = word2pdf(filename = file.rstrip('.docx'), doc = "N")else:rc = word2pdf(filename = file.rstrip('.doc'), doc = "Y")

2.c# 实现word批量转pdf

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading;
using Microsoft.Office.Interop.Word;namespace Word2Pdf
{class Program{public static Microsoft.Office.Interop.Word.Document wordDocument { get; set; }static void Main(string[] args){string strFolder_f = null;string strFolder_t = null;string strFlag = null;System.Console.WriteLine("请输入Word文档所在目录");strFolder_f = System.Console.ReadLine();if (strFolder_f.Substring(strFolder_f.Length - 1, 1) != "\\"){strFolder_f += "\\";}strFolder_t = strFolder_f + @"pdf\";System.Console.WriteLine("\n创建PDF文档,请确认!");System.Console.Write("y(yes) or n(no) ?  ");strFlag = System.Console.ReadLine();if (strFlag == "y"){System.Console.WriteLine("\n开始创建PDF文档...");CheckFolder(strFolder_t);string strPdfFile = null;DirectoryInfo TheFolder = new DirectoryInfo(strFolder_f);Microsoft.Office.Interop.Word.Application appWord = new Microsoft.Office.Interop.Word.Application();object paramMissing = Type.Missing;foreach (FileInfo NextFile in TheFolder.GetFiles()){strPdfFile = Path.ChangeExtension(strFolder_t + NextFile.Name, ".pdf");wordDocument = appWord.Documents.Open(NextFile.FullName);if (wordDocument != null){wordDocument.ExportAsFixedFormat(strPdfFile, WdExportFormat.wdExportFormatPDF);wordDocument.Close(ref paramMissing, ref paramMissing, ref paramMissing);wordDocument = null;}System.Console.Write(".. ");}if (appWord != null){appWord.Quit(ref paramMissing, ref paramMissing, ref paramMissing);appWord = null;}}//KillProcessByName("WINWORD");GC.Collect();GC.WaitForPendingFinalizers();System.Console.Write("\n处理完毕,输入任意键退出");System.Console.ReadKey();}static void CheckFolder(string strFolderPath){if (Directory.Exists(strFolderPath)){Directory.Delete(strFolderPath, true);Directory.CreateDirectory(strFolderPath);}else{Directory.CreateDirectory(strFolderPath);}}static void KillProcessByName(string name){Process[] ps = Process.GetProcessesByName(name);foreach (Process p in ps){if (p.ProcessName == name)p.Kill();}}}
}

python实现word批量转pdf相关推荐

  1. python制作合同模板带图片_办公自动化7_用Python操作Word批量生成合同

    ########## 实例7:用Python操作Word批量生成合同 ################ ''' 来源网上整理 ,供学习使用. 我们建立的模板和合同信息如下图所示:这里有几个注意事项: ...

  2. Word批量转PDF(内容转图片,防复制文字)

    一.软件下载地址 Word批量转PDF(内容转图片,防复制文字)(2021-07-13更新)下载地址: https://download.csdn.net/download/techinged/241 ...

  3. 一分钟玩转RPA——word批量转pdf

    大家好,我是无用兄,批量word转pdf文件我们在工作中有时会经常遇到,网上也有很多工具,有收费的也有免费的,今天我们主要介绍下如何用影刀RPA工具只需要四条指令就可以完成这个工作,而且后续的使用是完 ...

  4. 基于python的word批量图文排版

    1.缘起 在最近的工作中,需要将大量的图片按一定顺序在word里排版,并要求每页内容为:序号 + 图像文件名 + 图片.之前用VBA也实现了要求,但奈何对VBA不熟悉,不利于之后的扩展,因此看看万能的 ...

  5. 什么?你还不知道 Word 批量转 PDF?python来教你

    前言 现实中我们大多数人都做过将 Word 文件转成 PDF 文件的工作,如果需要转换的文件较少时,我们自己手动转没什么问题,但如果需要转换的文件比较多时,手动转起来也是一个不小的工作量,这时我们就需 ...

  6. php上传word并展示_这2种简单方法能将Word批量转换PDF

    目前PDF文档使用越来越多,但由于新建和编辑相对比较复杂,我们经常先用Word文档编辑好之后再转换成PDF格式,如果需要处理的文档较多,是否有快速批量处理的方法呢?下面介绍两种简单一键批量Word转P ...

  7. 1 Python 将word文件转换为PDF文件

    原文地址http://blog.csdn.net/rumswell/article/details/7434302 #-*- coding:utf-8 -*- # doc2pdf.py: python ...

  8. python ubuntu word txt 转pdf,python实现pdf转换成word/txt纯文本文件

    本文实例为大家分享了python实现pdf转word/txt,供大家参考,具体内容如下 依赖包:pdfminer3k 可以通过pip安装:也可以到下载,解压,进入文件夹,输入命令setup.py in ...

  9. Python教程:批量合成PDF

    分享一个实用的办公脚本:将多个PDF合并为一个PDF,例如我手上现在有如下3个PDF分册,需要整合成一个完整的PDF 如果换成你操作的话,是不是打开百度搜索:PDF合并,然后去第三方网站操作,可能会收 ...

  10. Word 批量转 PDF 方法, 杜绝耍手段的交费软件!

    1.将需要转PDF的文档放一个文件夹里, 2.复制下面代码到文本中,另存为xxx.vbs 文件(注意:类型选为所有文件), 3.放入word文件夹,双击运行. On Error Resume Next ...

最新文章

  1. static interface method calls are not supported at language level 1.6
  2. 把接口调用打成jar包的类怎么写_直观讲解RPC调用和HTTP调用的区别
  3. Linux与win2003下修改mac地址方法
  4. opencv 使用cvload加载xml出现错误原因解析及方法
  5. Java怎么在if输出中进行运算_磕代码:c/c++/java:输入三个整数,输出运算结果;if条件句的使...
  6. C语言浮点数据在内存中的存储方式
  7. 再有人问你volatile是什么,把这篇文章也发给他(深入分析)
  8. Python enumerate() 函数
  9. 3-39客户端(client)写数据到HDFS的流程
  10. 华为云GaussDB新产品特性亮相DTC2021,新品开源预告
  11. 最大熵模型介绍及实现
  12. 对 pretext tasks 的理解
  13. 龙芯2f笔记本安装debian错误--bzcat
  14. 三阶魔方大中小魔公式_七步玩转三阶魔方还原公式及非公式步骤图解【新手适用超详细】...
  15. 【GAN】Mode Collapse 和 Mode Dropping 问题定义
  16. iOS模拟键盘长按删除
  17. 类似PS的蒙版?可以实现,LVGL『Object mask对象蒙版控件』介绍
  18. 关于ERP系统提前期运算逻辑的三点介绍
  19. 微信公众平台接口,asp.net实现
  20. PCM音频文件格式的头信息

热门文章

  1. linux源码编译ipk,openwrt SDK, 利用SDK生成自己的ipk安装包
  2. 扣费克星-您的话费守护神 v1.42 新增联网程序管理扩展插件发布
  3. ubuntu安装ROS运行rosdep init错误,cannot download default sources list from....
  4. 采用加速度传感器的角度测量仪系统硬件电路设计_温度传感器电路
  5. 苹果错误分析报告preferreuserinterface_20182019年苹果产业链分析报告
  6. Echart 四象限图
  7. Android 开发框架xUtils3
  8. 保护你的端口(转自赛迪网)
  9. 阿里云OSS对象存储服务
  10. Python数据预处理--Gensim构建语料词典