word 文件转PDF 预览

//word 文件转PDF 预览
private readonly string Historyfile = Config.ConfigHelper.GetAppSetting<string>("Historyfile");

string filePath = "app/download/0a05e991bade4a2d9b0d13fd6d92760f.doc";
string wordFilePath = Path.Combine(Historyfile, filePath);
var ftype = Path.GetExtension(fileName);
if (ftype != ".pdf")
{
var pdfFilePath = wordFilePath.Replace(ftype, ".pdf");
bool b = WordToPdf(wordFilePath, pdfFilePath);
if (!b)
{
return HttpNotFound();
}
return File(pdfFilePath, "application/octet-stream", Url.Encode(fileName));
}

public bool WordToPdf(string wordFilePath, string pdfFilePath)
{
try
{
var doc = new Aspose.Words.Document(wordFilePath);
doc.Save(pdfFilePath, Aspose.Words.SaveFormat.Pdf);
return true;
}
catch
{
return false;
}
}

原文地址:https://www.cnblogs.com/chengzi00/p/14447702.html