引用 Microsoft.Office.Interop.Word 这个dll,可以在解决方案浏览器中搜索到并下载。

源码如下:

public bool WordToPDF(string sourcePath)
{
bool result = false;
Microsoft.Office.Interop.Word.Application application = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document document = null;
try
{
application.Visible = false;
document = application.Documents.Open(sourcePath);
string PDFPath = sourcePath.Replace(".doc", ".pdf");//pdf存放位置
if (!File.Exists(@PDFPath))//存在PDF,不需要继续转换
{
document.ExportAsFixedFormat(PDFPath, Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF);
}
result = true;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
result = false;
}
finally
{
document.Close();
}
return result;
}

摘自https://www.cnblogs.com/alannxu/p/10972947.html

最新文章

  1. CentOS下配置java环境变量classpath
  2. ASP.NET MVC之国际化(十一)
  3. 评价cnblogs.com的用户体验
  4. Bootstrap 表单
  5. mysql 优化配置参数详解
  6. poj3371
  7. 算法与数据结构题目的 PHP 实现:栈和队列 设计一个有 getMin 功能的栈
  8. MapReduce编程系列 — 6:多表关联
  9. Sqlserver中关于锁
  10. mysql主从之主键冲突
  11. Python自动化运维之14、设计模式
  12. css--左右visibility建立 “collapse”值问题
  13. 【 js 基础 】 深浅拷贝
  14. Python正则表达式返回首次匹配到的字符及查询的健壮性
  15. scrapy---callback 传递自定义参数
  16. java的迭代器详解
  17. FZU 2285 迷宫寻宝
  18. springboot2.0以后WebMvcConfigurationSupport代替WebMvcConfigurationAdapter
  19. HTML和CSS查缺补漏
  20. django之两个使用模板的例子

热门文章

  1. 关与 @EnableConfigurationProperties 注解
  2. JS格式化JSON串显示在表格中
  3. 一个简单servlet容器
  4. Linux framebuffer deferred io机制【转】
  5. Linux7/Centos7用户密码安全
  6. 基于VLC库C#开发可播放摄像头及任意格式视频的播放器
  7. 【使用篇二】SpringBoot文件上传(5)
  8. http协议里定义的四种常见数据的post方法
  9. [LeetCode] 33. Search in Rotated Sorted Array 在旋转有序数组中搜索
  10. 把 DataTable 输出到 excel 文件