C# word格式转换为pdf
2024-09-06 01:41:20
引用 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
最新文章
- CentOS下配置java环境变量classpath
- ASP.NET MVC之国际化(十一)
- 评价cnblogs.com的用户体验
- Bootstrap 表单
- mysql 优化配置参数详解
- poj3371
- 算法与数据结构题目的 PHP 实现:栈和队列 设计一个有 getMin 功能的栈
- MapReduce编程系列 — 6:多表关联
- Sqlserver中关于锁
- mysql主从之主键冲突
- Python自动化运维之14、设计模式
- css--左右visibility建立 “collapse”值问题
- 【 js 基础 】 深浅拷贝
- Python正则表达式返回首次匹配到的字符及查询的健壮性
- scrapy---callback 传递自定义参数
- java的迭代器详解
- FZU 2285 迷宫寻宝
- springboot2.0以后WebMvcConfigurationSupport代替WebMvcConfigurationAdapter
- HTML和CSS查缺补漏
- django之两个使用模板的例子
热门文章
- 关与 @EnableConfigurationProperties 注解
- JS格式化JSON串显示在表格中
- 一个简单servlet容器
- Linux framebuffer deferred io机制【转】
- Linux7/Centos7用户密码安全
- 基于VLC库C#开发可播放摄像头及任意格式视频的播放器
- 【使用篇二】SpringBoot文件上传(5)
- http协议里定义的四种常见数据的post方法
- [LeetCode] 33. Search in Rotated Sorted Array 在旋转有序数组中搜索
- 把 DataTable 输出到 excel 文件