搜房网666装修,婴儿奶粉品牌排行榜,痞子英雄迅雷下载
1.使用 office com组件的microsoft.office.interop.word.dll库
该方法需要在电脑上安装office软件,并且需要office支持转换为pdf格式,如果不支持,从官网下载一个saveaspdfandxps.exe插件
interop.word程序集可以通过nuget程序包获取,实现代码如下:
public bool wordtopdf2(string sourcepath)
{
bool result = false;
word.application application = new word.application();
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, word.wdexportformat.wdexportformatpdf);
}
result = true;
}
catch (exception e)
{
console.writeline(e.message);
result = false;
}
finally
{
document.close();
}
return result;
}
2.使用aspose.words组件
首先需要引用aspose.words.dll,链接地址:https://pan.baidu.com/s/1rjvjp-kmseteryf_oud28q 提取码:awiw
代码如下:
public bool wordtopdf1(string sourcepath)
{
try
{
document doc = new document(sourcepath);
string targetpath = sourcepath.toupper().replace(".docx", ".pdf");
doc.save(targetpath,saveformat.pdf);
}
catch(exception e)
{
console.writeline(e.message);
return false;
}
return true;
}
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Net Core Web Api项目与在NginX下发布的方法
asp.net core3.1 引用的元包dll版本兼容性问题解决方案
IdentityServer4实现.Net Core API接口权限认证(快速入门)
ASP.NET Core MVC通过IViewLocationExpander扩展视图搜索路径的实现
网友评论