首页 新闻 会员 周边 捐助

C#,利用 Microsoft.Office.Core,将word转pdf,word中有个特殊字体,在本地和服务器上都加上了该字体,但是转完之后,在本地可以,在服务器字体不是原来word的字体了

0
悬赏园豆:20 [已关闭问题] 关闭于 2020-04-15 09:23

这是我word转pdf的方法,求大神指导private string WORDHTML(string FilePath, string FileName, string Name)
{
Word.ApplicationClass word = new Word.ApplicationClass();
Type wordType = word.GetType();
try
{
//存放word文件的完整路径
string wordPath = Server.MapPath(FilePath + FileName);
string FanHuiLuJing = "/html/TOHTML/" + Guid.NewGuid().ToString().ToUpper();
//判断路径是否存在,不存咋创建
string FileFullPath = Server.MapPath(FanHuiLuJing);
if (!Directory.Exists(FileFullPath))
{
Directory.CreateDirectory(FileFullPath);
}
//判断结尾是否是"/"
if (FanHuiLuJing.EndsWith("/") == false)
{
FanHuiLuJing = FanHuiLuJing + "/";
}
//存放html文件的完整路径
string htmlPath = Server.MapPath(FanHuiLuJing) + Name;
Word.Documents docs = word.Documents;
// 打开文件
Type docsType = docs.GetType();
object fileName = wordPath;
Word.Document doc = (Word.Document)docsType.InvokeMember("Open", BindingFlags.InvokeMethod, null, (object)docs, new Object[] { fileName, true,true});
//每一个html文件,有一个对应的存放html相关元素的文件夹(html文件名.files)
if (Directory.Exists(htmlPath.Replace(".html", ".files")))
{
Directory.Delete(htmlPath.Replace(".html", ".files"), true);
}
//转换格式,调用word的“另存为”方法
Type docType = doc.GetType();
object saveFileName = htmlPath; //"f:\aaa.html";
docType.InvokeMember("SaveAS", BindingFlags.InvokeMethod, null, doc, new object[] { saveFileName, Word.WdSaveFormat.wdFormatPDF });
// 退出 Word
wordType.InvokeMember("Quit", BindingFlags.InvokeMethod, null, word, null);
//word.Quit();
GC.Collect();
return "../../ShareUpload/PDFYuLan?FilePath=" + "../.." + FanHuiLuJing + Name + ".pdf";
}
catch (Exception e)
{
//wordType.InvokeMember("Quit", BindingFlags.InvokeMethod, null, word, null);
//word.Quit();
GC.Collect();
return "[]";
}
}

haodejiuzheyangba的主页 haodejiuzheyangba | 初学一级 | 园豆:142
提问于:2020-03-26 16:06
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册