运行环境:office2010或office2007+SaveAsPDFandXPS.exe补丁 x86x64系统环境均可。
class Program
{
static void Main(string[] args)
{
DOCConvertToPDF(AppDomain.CurrentDomain.BaseDirectory + "/b.html", AppDomain.CurrentDomain.BaseDirectory + "/aa.pdf");
Console.ReadKey();
}
//Word转换成pdf
/// <summary>
/// 把Word文件转换成为PDF格式文件
/// </summary>
/// <param name="sourcePath">源文件路径</param>
/// <param name="targetPath">目标文件路径</param> 
/// <returns>true=转换成功</returns>
public static bool DOCConvertToPDF(string sourcePath, string targetPath)
{
bool result = false;
Microsoft.Office.Interop.Word.WdExportFormat exportFormat = Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF;
object paramMissing = Type.Missing;
Microsoft.Office.Interop.Word.ApplicationClass wordApplication = new Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document wordDocument = null;
try
{
object paramSourceDocPath = sourcePath;
string paramExportFilePath = targetPath;
Microsoft.Office.Interop.Word.WdExportFormat paramExportFormat = exportFormat;
bool paramOpenAfterExport = false;
Microsoft.Office.Interop.Word.WdExportOptimizeFor paramExportOptimizeFor = Microsoft.Office.Interop.Word.WdExportOptimizeFor.wdExportOptimizeForPrint;
Microsoft.Office.Interop.Word.WdExportRange paramExportRange = Microsoft.Office.Interop.Word.WdExportRange.wdExportAllDocument;
int paramStartPage = 0;
int paramEndPage = 0;
Microsoft.Office.Interop.Word.WdExportItem paramExportItem = Microsoft.Office.Interop.Word.WdExportItem.wdExportDocumentContent;
bool paramIncludeDocProps = true;
bool paramKeepIRM = true;
Microsoft.Office.Interop.Word.WdExportCreateBookmarks paramCreateBookmarks = Microsoft.Office.Interop.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,
WdOpenFormat.wdOpenFormatWebPages
, 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);
Console.WriteLine("success!");
result = true;
}
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace);
result = false;
}
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;
}
}

.Net 调用wordCOM组件转PDF相关推荐

  1. 调用WPS服务COM组件转换PDF

    由于从客户有可能上传各中类型的附件,那么在客户实现在线阅览就必须统一格式.基本实现方式就是把所有各种类型文件转换成pdf.然后使用SWFTool把pdf转换成.swf播放文件.在客户端安装flash播 ...

  2. 使用免费组件给PDF文档添加文本和图片页眉

    C#/.NET 使用免费组件给PDF文档添加文本和图片页眉 如今PDF文档与Office文档一样成为了一种通用文档,在日常工作中我们经常会碰到需要给PDF文件添加页眉和页脚/页码等情况,如果你正好是喜 ...

  3. vue-pdf 组件实现 pdf预览效果+点击打印按钮直接弹窗打印指定pdf文件

    预览效果图: 打印指定文件效果图: 点击按钮 直接弹出该打印页面: 依赖: 实现预览+打印功能: npm install --save vue-pdf 代码: 打印部分:<a-button @c ...

  4. Vue子组件调用父组件方法并传参的5种方式:$emit触发、传入子组件function、访问父组件$parent.function、用inject关联父组件provide的方法、用window.fun

    如需了解老子怎么控制儿子的,传送门:https://s-z-q.blog.csdn.net/article/details/119922715 子组件child.vue <template> ...

  5. Vue父组件调用子组件的方法并传参的两种方式(用$refs.refName.functionName、window.function)

    如需了解儿子怎么控制老子的,传送门:https://s-z-q.blog.csdn.net/article/details/120094689 父组件father.vue <template&g ...

  6. vue父组件调用子组件的方法

    vue组件与组件通信有如下几种情况: 平行组件 父组件与子组件 子组件与父组件 它们之间通信有几种方法有: props 自定义事件 vuex 今天我们聊一下父组件调用子组件的一种方法 parent.v ...

  7. Win10系列:VC++调用自定义组件1

    通过20.9.1小节中的代码和步骤编写了一个名为"FilePickerComponent"的WinRT组件,接下来将在上一小节所新建的项目基础上,继续介绍如何在不同的语言所编写的应 ...

  8. C#调用COM组件遇到的问题及解决办法

    C#调用COM组件遇到的问题及解决办法 参考文章: (1)C#调用COM组件遇到的问题及解决办法 (2)https://www.cnblogs.com/yuzhihui/p/9777323.html ...

  9. 【Flutter】自定义 Flutter 组件 ( 创建自定义 StatelessWidget、StatefulWidget 组件 | 调用自定义组件 )

    文章目录 一.Flutter 组件简介 二.Flutter 自定义 StatelessWidget 组件流程 1.导入父类包 2.选择继承的父类 3.设置成员变量及构造函数 4.重写 build 方法 ...

最新文章

  1. Centos7为普通用户添加sudo权限
  2. CSS篇 第9章 Visual Formatting Model 部分翻译
  3. amd为什么还用针脚_英特尔的针脚都取消了,为什么AMD的还没动静?
  4. 数学建模学习笔记(三)——插值算法
  5. [文摘20071127]推销场上的十种失败的推销员
  6. android webview的一些设置问题
  7. 每天一个linux命令(60):scp命令
  8. 顺序不能改变的算子,是否跟时间有关
  9. Unity(十九):获取编辑器内置样式和内置图标
  10. Mac开发-脚本打包DMG
  11. Flutter支付宝授权登录
  12. 03一般过去时和主谓双宾
  13. 设置标题栏背景色,背景色是自定义背景色
  14. SD从零开始10 框架协议(Outline Agreement)—合同/计划协议
  15. 强大的安全工具 杀毒软件小红伞试用测评
  16. 复习DOS及批处理命令
  17. 新手零基础21天Python打卡计划开始啦
  18. 蒲江县实验中学计算机老师照片,上“新”!实验中学一批高能教师亮相!
  19. carbondata使用笔记
  20. ORA-22858: 数据类型的变更无效 varchar2类型转换为clob类型

热门文章

  1. 前端学习(2689):重读vue电商网站10之表格展开页
  2. 工作45:注意公用方法 别混入
  3. 前端学习(2235):react的列表渲染
  4. 前端学习(2152):Vue的template和el的关系
  5. 这篇看完我得理解ES6中中常见语法
  6. 前端学习(642):字面量
  7. spring mvc学习(45):springMVC的三大组件
  8. java学习(98):线程join使用中断进行另一个
  9. Python sqrt() 函数
  10. 电脑表格日期怎么修改原有日期_为何电脑系统时间常出错或无法修改?怎么解决?...