C#实现Office文档转Pdf的方法
需要安装office 2007 还有一个office2007的插件OfficeSaveAsPDFandXPS
using Excel = Microsoft.Office.Interop.Excel;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
//将word文档转换成PDF格式private bool Convert(string sourcePath, string targetPath, Word.WdExportFormat exportFormat){bool result;object paramMissing = Type.Missing;Word.ApplicationClass wordApplication = new Word.ApplicationClass();Word.Document wordDocument = null;try{object paramSourceDocPath = sourcePath;string paramExportFilePath = targetPath;Word.WdExportFormat paramExportFormat = exportFormat;bool paramOpenAfterExport = false;Word.WdExportOptimizeFor paramExportOptimizeFor =Word.WdExportOptimizeFor.wdExportOptimizeForPrint;Word.WdExportRange paramExportRange = Word.WdExportRange.wdExportAllDocument;int paramStartPage = 0;int paramEndPage = 0;Word.WdExportItem paramExportItem = Word.WdExportItem.wdExportDocumentContent;bool paramIncludeDocProps = true;bool paramKeepIRM = true;Word.WdExportCreateBookmarks paramCreateBookmarks =Word.WdExportCreateBookmarks.wdExportCreateWordBookmarks;bool paramDocStructureTags = true;bool paramBitmapMissingFonts = true;bool paramUseISO19005_1 = false;wordDocument = wordApplication.Documents.Open(ref paramSourceDocPath, ref paramMissing, ref paramMissing,ref paramMissing, ref paramMissing, ref paramMissing,ref paramMissing, ref paramMissing, ref paramMissing,ref paramMissing, ref paramMissing, ref paramMissing,ref paramMissing, ref paramMissing, ref paramMissing,ref paramMissing);if (wordDocument != null)wordDocument.ExportAsFixedFormat(paramExportFilePath,paramExportFormat, paramOpenAfterExport,paramExportOptimizeFor, paramExportRange, paramStartPage,paramEndPage, paramExportItem, paramIncludeDocProps,paramKeepIRM, paramCreateBookmarks, paramDocStructureTags,paramBitmapMissingFonts, paramUseISO19005_1,ref paramMissing);result = true;}finally{if (wordDocument != null){wordDocument.Close(ref paramMissing, ref paramMissing, ref paramMissing);wordDocument = null;}if (wordApplication != null){wordApplication.Quit(ref paramMissing, ref paramMissing, ref paramMissing);wordApplication = null;}GC.Collect();GC.WaitForPendingFinalizers();GC.Collect();GC.WaitForPendingFinalizers();}return result;}//将excel文档转换成PDF格式private bool Convert(string sourcePath, string targetPath, XlFixedFormatType targetType){bool result;object missing = Type.Missing;Excel.ApplicationClass application = null;Workbook workBook = null;try{application = new Excel.ApplicationClass();object target = targetPath;object type = targetType;workBook = application.Workbooks.Open(sourcePath, missing, missing, missing, missing, missing,missing, missing, missing, missing, missing, missing, missing, missing, missing);workBook.ExportAsFixedFormat(targetType, target, XlFixedFormatQuality.xlQualityStandard, true, false, missing, missing, missing, missing);result = true;}catch{result = false;}finally{if (workBook != null){workBook.Close(true, missing, missing);workBook = null;}if (application != null){application.Quit();application = null;}GC.Collect();GC.WaitForPendingFinalizers();GC.Collect();GC.WaitForPendingFinalizers();}return result;}//将ppt文档转换成PDF格式private bool Convert(string sourcePath, string targetPath, PpSaveAsFileType targetFileType){bool result;object missing = Type.Missing;PowerPoint.ApplicationClass application = null;Presentation persentation = null;try{application = new PowerPoint.ApplicationClass();persentation = application.Presentations.Open(sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);persentation.SaveAs(targetPath, targetFileType, Microsoft.Office.Core.MsoTriState.msoTrue);result = true;}catch{result = false;}finally{if (persentation != null){persentation.Close();persentation = null;}if (application != null){application.Quit();application = null;}GC.Collect();GC.WaitForPendingFinalizers();GC.Collect();GC.WaitForPendingFinalizers();}return result;}
C#实现Office文档转Pdf的方法相关推荐
- 仿百度文库方案[openoffice.org 3+swftools+flexpaper](三) 之 使用JODConverter将office文档转换为pdf...
第三步,使用JODConverter将office文档转换为pdf JODConverter是一个java的OpenDucument文件转换器,可以进行许多文件格式的转换,它利用 OpenOffice ...
- java零碎要点010---Java实现office文档与pdf文档的在线预览功能
最近项目有个需求要java实现office文档与pdf文档的在线预览功能,刚刚接到的时候就觉得有点难,以自己的水平难以在三四天做完.压力略大.后面查找百度资料.以及在同事与网友的帮助下,四天多把它做完 ...
- C#实现office文档转换为PDF格式
C#实现office文档转换为PDF格式 1.安装组件OfficeSaveAsPDFandXPS 需要安装office 2007 还有一个office2007的插件OfficeSaveAsPDFand ...
- java 预览word文档_Java实现office文档与pdf文档的在线预览功能
最近项目有个需求要java实现office文档与pdf文档的在线预览功能,刚刚接到的时候就觉得有点难,以自己的水平难以在三四天做完.压力略大.后面查找百度资料.以及在同事与网友的帮助下,四天多把它做完 ...
- python将文档转换成pdf_Python实现将DOC文档转换为PDF的方法
本文实例讲述了Python实现将DOC文档转换为PDF的方法.分享给大家供大家参考.具体实现方法如下: import sys, os from win32com.client import Dispa ...
- Android实现在线预览office文档(Word,Pdf,excel,PPT.txt等格式)
1.概述 我们都知道,Android原生并没有提供浏览office文档格式的相关Api,在安卓端想要实现在线预览office文档的功能显然很是复杂,我们手机安装QQ浏览器时,在手机打开office文档 ...
- 永中word页码怎么从第二页开始_快捷的word文档转pdf好方法推荐
阅读本文前,请您先点击上面的"蓝色字体",再点击"关注",这样您就可以继续免费收到文章了.每天都会有分享,都是免费订阅,请您放心关注.注图文来源网络,侵删 wo ...
- linux平台的office文档转pdf的实例(程序员的菜)
需要材料: 1. Openoffice3.4(我是32位的centos,可以根据自己的系统下载指定的openoffice软件包) 下载地址:http://sourceforge.net/project ...
- java命令行利用libreoffice将office文档转换为pdf文件失败的解决方案
原因:libreoffice同时只支持两个文档转换的命令行,多于两个的命令行不会进行文档转换. 解决方案:在线程池的线程中,利用java阻塞队列BlockingQueue,设置容量为2,同时只允许两个 ...
最新文章
- #418 Div2 Problem B An express train to reveries (构造 || 全排列序列特性)
- 实时音视频技术的演进与应用
- 快手搜索技术部招聘NLP算法工程师!
- 一次完整的http请求
- JDK9.0.4安装配置
- 八、Python 之内置函数(。。。)
- 《构建之法》8、9、10
- 【Java笔记】Java开发实战经典 - 第六章
- PDF Explained(翻译)第一章 简介
- 小米Miui线刷步骤记录
- java pdf转png格式_如何在Java中将PDF转换为PNG或JPG
- 使用echarts生成海友网企业全国分布地图
- AR增强现实技术解读
- 腾讯3轮面试都问了Android事件分发,最强技术实现
- 使用OBS录屏有很大的电流回声
- 一个使用LABVIEW将16进制字符串分割转化的办法
- python excel画图
- android CMWAP, CMNET有何区别
- SQL1 插入记录(一)
- 使用虚拟信用卡在Allegro下单测试教程
热门文章
- tensorflow 测试 cuda 是否安装成功,测试代码环境
- AcWing算法基础课 Level-2 第三讲 搜索与图论
- SpringBoot笔记:SpringBoot启动参数配置
- Commit failed with error: pathspec 'src/main/java/com/leo/demo/juctest/test.java' did not match any
- 读取文件夹下所有的文件
- 你有没有遇到要实现多种登录方式的场景丫 一起来看看咯 Spring Security 实现多种登录方式,如常规方式外的邮件、手机验证码登录
- ecshop 搜索热词推荐_拼多多搜索推广实操——如何选择正确的关键词实现高投产!...
- 手机连接不上电脑只显示充电_INNOCN N1G便携显示器,解决孩子和大人多重使用需求...
- 项目收获与体会_践行“十个一”在劳动中收获成长——青岛六十六中高二年级学农实践活动圆满结束...
- java动效_Android 界面漩涡扭曲动效实现