ASP.NET Word轉為PDF
1、首先安裝 Microsoft Office 2007加載項:Microsoft Save as PDF-簡體中文版:下載地址:
http://download.microsoft.com/download/3/8/8/388812b2-0d3f-474e-a7ef-b095d3d0d3cd/SaveAsPDF.exe
2,代碼如下
/// <summary>
/// 轉換word為pdf
/// </summary>
/// <param name="filename">doc文件路徑</param>
/// <param name="savefilename">pdf保存路徑</param>
void ConvertWordPDF1(object filename, object savefilename)
{
Object Nothing = System.Reflection.Missing.Value;
//創建一個名為WordApp的組件對象
wordApp = new ApplicationClass();
//創建一個名為WordDoc的文檔對象并打開
Document doc = wordApp.Documents.Open(ref filename, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
//設置保存的格式
object filefarmat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;
//保存為PDF
doc.SaveAs(ref savefilename, ref filefarmat, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
//關閉文檔對象
doc.Close(ref Nothing, ref Nothing, ref Nothing);
//推出組建
wordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
doc = null;
wordApp = null;
}
//下面是各種轉換格式
object filefarmat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;//設置保存的格式,還可以為以下格式:
Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML //保存為HTML
Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatRTF //保存為RTF
Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatText //保存為文本
Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatXML //保存為XML
Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatXPS //保存為XPS
玉環人力網(又名玉環人才網)是玉環人才吧旗下一流的玉環人力資源招聘行業服務品牌,匯集海量玉環人才,開放玉環人才簡歷和玉環崗位,提供玉環招聘網,玉環人才市場動態行情,玉環勞務派遣,玉環培訓等,是玉環最大的人才網站。
浙公網安備 33010602011771號