-
2018-07-13 08:47:22
python源码实现doc转化pdf
#-*- coding:utf-8 -*- # doc2pdf.py: python script to convert doc to pdf with bookmarks! # Requires Office 2007 SP2 # Requires python for win32 extension import sys, os from win32com.client import Dispatch, constants, gencache def doc2pdf(input, output): w = Dispatch("Word.Application") try: doc = w.Documents.Open(input, ReadOnly = 1) doc.ExportAsFixedFormat(output, constants.wdExportFormatPDF,\ Item = constants.wdExportDocumentWithMarkup, CreateBookmarks = constants.wdExportCreateHeadingBookmarks) return 0 except: return 1 finally: w.Quit(constants.wdDoNotSaveChanges) # Generate all the support we can. def GenerateSupport(): # enable python COM support for Word 2007 # this is generated by: makepy.py -i "Microsoft Word 12.0 Object Library" gencache.EnsureModule('{00020905-0000-0000-C000-000000000046}', 0, 8, 4) def main(): print(len(sys.argv)) if (len(sys.argv) == 2): input = sys.argv[1] output = os.path.splitext(input)[0]+'.pdf' elif (len(sys.argv) == 3): input = sys.argv[1] output = sys.argv[2] else: input = u'BA06007013.docx'#word文档的名称 output = u'BA06007013.pdf'#pdf文档的名称 if (not os.path.isabs(input)): input = os.path.abspath(input) if (not os.path.isabs(output)): output = os.path.abspath(output) try: GenerateSupport() rc = doc2pdf(input, output) return rc except: return -1 if __name__=='__main__': print("hello") rc = main() if rc: sys.exit(rc) sys.exit(0)
更多相关内容 -
Doc2PDF-crx插件
2021-04-04 06:31:52Doc2PDF Converter允许将任何文件从任务栏图标快速转换为PDF Doc2Pdf允许您直接从浏览器操作按钮轻松地将文件转换为PDF格式,而无需任何应用程序。 现在享受立即使用免费的PDF转换器。 轻松在Doc和PDF文件之间转换。... -
doc2pdf2 doc/word转pdf
2014-05-24 12:23:12doc2pdf2 doc/word转pdf -
doc2pdf.exe
2019-01-20 17:41:52doc资料文件 -
doc2pdf2 word转PDF
2013-08-22 11:28:34doc2pdf2 word转PDF工具 -
doc2pdf_src.zip
2020-09-03 17:55:56import com.spire.doc.*; /* * @version V1.0 */ public class ToPDF { public static void main(String[] args) { long start = System.currentTimeMillis(); String inputFile="D:\\home\\da_data\\Sample.... -
Python实现将doc转化pdf格式文档的方法
2020-12-25 15:41:30# doc2pdf.py: python script to convert doc to pdf with bookmarks! # Requires Office 2007 SP2 # Requires python for win32 extension import sys, os from win32com.client import Dispatch, constants, ... -
doc2pdf工具
2012-11-04 11:38:56轻松将doc转化为pdf,大家可以安全放心下载哦 -
FlashPaper2.2 doc2pdf doc2swf office2swf office2pdf
2010-12-08 23:01:09FlashPaper2.2 doc2pdf doc2swf office2swf office2pdf word文档转换成swf,PDF格式 如获珍宝 -
利用jodconverter--doc2pdf
2012-02-24 15:57:50利用jodconverter--doc2pdf -
调用WPS2012实现DOC2PDF示例
2012-05-24 22:02:51演示了两种利用WPS导出PDF的方法,需要安装WPS2012. 参考了网上的方法,增加了设置PDF保护选项、关闭文档、退出WPS。如果需要强制退出WPS进程(即程序退出了但WPS进程还在,请参考我以前的代码中的写法,获取进程ID... -
doc2pdf2_setup
2007-12-07 16:08:30WORD文件转换PDF格式 -
doc 替换生成doc doc转pdf实践
2019-12-07 17:04:12包含了doc 替换生成doc doc转pdf生成需要的jar和 doc模板 为毛要50个字 有病 -
doc2pdf_setup.zip
2009-03-03 13:09:45Convert Doc to PDF For Word可以快速而又花费低廉创建有专业水准的PDF文档。它的界面非常简单,你只需点击Word中的“Save as PDF”就可以把Ms Word文档保存为标准PDF文档。Convert Doc to PDF For Word支持字体的... -
Python实现将DOC文档转换为PDF的方法
2020-09-21 21:08:06主要介绍了Python实现将DOC文档转换为PDF的方法,涉及Python调用系统win32com组件实现文件格式转换的相关技巧,需要的朋友可以参考下 -
doc/docx转pdf工具
2018-10-29 17:44:50一个可以运行在win7下的word文档转pdf小工具,需要已经安装office2013 -
DOC转PDF工具
2019-06-04 23:39:29DOC转PDF工具,用于软件中编写帮助文档,只读文档等。 -
word2pdf word转pdf word批量转pdfbatchwork.doc.to.pdf.converter工具 软件.zip
2020-03-11 17:49:15最好的 最好用的 word2pdf 工具 软件 word转pdf word批量转pdf batchwork.doc.to.pdf.converter.cr 资源管理器 内含安装步骤安装方案 安装完毕后为正版 xp win7 win8 win10均可用 支持资源管理器右键菜单 -
docx、doc转pdf
2016-12-08 10:38:02docx、doc转pdf,在com.converterPdf.DocTest.java 修改下路径运行main方法就可以了。里面jar包什么都有了,亲测可以,是ok的。 -
gs811w32 doc2pdf
2009-04-23 14:47:36WORD转换为pdf工具软件.要找postscript呀.找不到哟. -
自制DOCTOPDF
2017-12-18 09:14:28自制DOCTOPDF,非开源,非免费,非完整,不建议下载~浪费分 -
java word(doc,docx,rtf)转为pdf
2019-03-12 15:24:46java word(doc,docx,rtf)转为pdf 包含源码,jar,可以直接运行 -
java实现doc、xls等格式转换pdf,实现在线浏览
2020-01-03 11:17:40使用poi、itextpdf实现doc、xls、xlsx、txt、图片、txt等等格式转换pdf,实现在线浏览功能 -
html2pdf_xls_doc.rar
2020-05-05 12:41:53html 转换 为 pdf, xlsx, doc等文件, 里面包含poi-3.15.jar, iText-2.0.8.jar,core-renderer.jar -
Doc to PDF Converter-crx插件
2021-03-23 01:40:09无需安装任何软件即可立即在线将您的Doc文档(word 97-2003)转换为PDF文件格式! 无需安装任何软件即可轻松地在线将doc文档(word 97-2003)转换为pdf文件格式。 单击扩展名图标后,将打开一个在线实用程序,您可以... -
Spire.Doc 和 PDF
2020-12-11 14:22:21Spire.Doc 和 PDF.7z 可用的版本 PDF 请注意调用方式 请注意调用方式 请注意调用方式 请注意调用方式 -
Java word(doc/docx)转pdf 无水印/免费
2021-01-10 16:26:33最近项目有个需求需要将word转为pdf。 网络上有好多种方案:spire,aspose,jacob等,由于jacob需要在jdk添加dll文件,有点束缚,所以在这里就不讲这个方案了 一.spire.doc 1.引入jar包 e-iceblue spire.doc.free ...最近项目有个需求需要将word转为pdf。
网络上有好多种方案:spire,aspose,jacob等,由于jacob需要在jdk添加dll文件,有点束缚,所以在这里就不讲这个方案了
一.spire.doc1.引入jar包
<dependencies> <dependency> <groupId>e-iceblue</groupId> <artifactId>spire.doc.free</artifactId> <version>3.9.0</version> </dependency> </dependencies> <repositories> <repository> <id>com.e-iceblue</id> <url>http://repo.e-iceblue.cn/repository/maven-public/</url> </repository> </repositories>
2.wordtopdfutil
public class WordToPdfUtil2 { public static void word2pdf(String inPath, String outPath) throws Exception { Document document = new Document(); document.loadFromFile(inPath); document.saveToFile(outPath, FileFormat.PDF); } public static void word2pdf(String inPath, OutputStream outputStream){ Document document = new Document(); document.loadFromFile(inPath); document.saveToStream(outputStream,FileFormat.PDF); } }
3.测试
public static void main(String[] args) { //aspose // String docPath = "C:\\Users\\linxishui\\Desktop\\test1.doc"; // String pdfPath = "C:\\Users\\linxishui\\Desktop\\test.pdf"; // WordToPdfUtil.doc2pdf(docPath,pdfPath); //spire String docPath2 = "C:\\Users\\linxishui\\Desktop\\test1.doc"; String pdfPath2 = "C:\\Users\\linxishui\\Desktop\\test2.pdf"; try { WordToPdfUtil2.word2pdf(docPath2,pdfPath2); } catch (Exception e) { e.printStackTrace(); } }
4.效果
word:
pdf:
5.限制
此种方法为免费的,但是限制每次只能打印3页,超过三页后就不给打了,
免费的就是这样的啦,不然人家花钱版的怎么卖的出去嘞,价格6000/年起步,
我这个穷人家是买不起的啦,所以有了下面的一种方法二.aspose
1.引入jar包
<dependencies> <dependency> <groupId>com.aspose</groupId> <artifactId>aspose-words</artifactId> <version>18.6</version> <classifier>jdk16</classifier> </dependency> </dependencies>
这里注意:这个jar包如果不是pj后的,而是直接从maven拉下来的话,
虽然没有了页数限制,但是页面顶端会有一行广告水印哦,我这里用的
是pj版本配合license验证使用的
2.wordtopdfutilpublic class WordToPdfUtil { public static boolean getLicense() { boolean result = false; try { InputStream is = Test.class.getClassLoader().getResourceAsStream("\\license.xml"); License aposeLic = new License(); aposeLic.setLicense(is); result = true; } catch (Exception e) { e.printStackTrace(); } return result; } public static boolean doc2pdf(String inPath, String outPath) { if (!getLicense()) { // 验证License 若不验证则转化出的pdf文档会有水印产生 return false; } FileOutputStream os = null; try { long old = System.currentTimeMillis(); File file = new File(outPath); // 新建一个空白pdf文档 os = new FileOutputStream(file); Document doc = new Document(inPath); // Address是将要被转化的word文档 doc.save(os, SaveFormat.PDF);// 全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, long now = System.currentTimeMillis(); System.out.println("pdf转换成功,共耗时:" + ((now - old) / 1000.0) + "秒"); // 转化用时 } catch (Exception e) { e.printStackTrace(); return false; }finally { if (os != null) { try { os.flush(); os.close(); } catch (IOException e) { e.printStackTrace(); } } } return true; } }
3.测试
public static void main(String[] args) { public static void main(String[] args) { //aspose String docPath = "C:\\Users\\linxishui\\Desktop\\test1.doc"; String pdfPath = "C:\\Users\\linxishui\\Desktop\\test.pdf"; WordToPdfUtil.doc2pdf(docPath,pdfPath); //spire // String docPath2 = "C:\\Users\\linxishui\\Desktop\\test1.doc"; // String pdfPath2 = "C:\\Users\\linxishui\\Desktop\\test2.pdf"; // try { // WordToPdfUtil2.word2pdf(docPath2,pdfPath2); // } catch (Exception e) { // e.printStackTrace(); // } }
4.效果
word:
pdf:
5.限制
这种方法是我目前找到的最实惠好用的一种了,限制就是要找到pj包了,我找了好久,这里我就不传播了总结:此两种方法都比较简单,好用,而且window,linux版本都适用,如果linux上转换有乱码的话,装一下windows字体就行了
这里推荐一篇装windows字体博客:https://blog.csdn.net/neulily2005/article/details/106003527 -
C#编程读取文档Doc、Docx及Pdf内容的方法
2020-12-26 02:01:25本文实例讲述了C#编程读取文档Doc、Docx及Pdf内容的方法。分享给大家供大家参考。具体分析如下: Doc文档:Microsoft Word 14.0 Object Library (GAC对象,调用前需要安装word。安装的word版本不同,COM的版本号也会...
收藏数
108,253
精华内容
43,301