国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

ASP.NET將word文檔轉換成pdf的代碼

2019-11-17 01:49:34
字體:
來源:轉載
供稿:網友
asp.net將Word文檔轉換成pdf的代碼

一、添加引用

using Microsoft.Office.Interop.Word;

二、轉換方法

1、方法

C# 代碼 復制
/// <summary>    /// 把Word文件轉換成pdf文件    /// </summary>    /// <param name="sourcePath">需要轉換的文件路徑和文件名稱</param>    /// <param name="targetPath">轉換完成后的文件的路徑和文件名名稱</param>    /// <returns>成功返回true,失敗返回false</returns>    public static bool WordToPdf(string sourcePath, string targetPath)    {        bool result = false;        WdExportFormat wdExportFormatPDF = WdExportFormat.wdExportFormatPDF;//轉換格式1.wdExportFormatPDF轉換成pdf格式 2.wdExportFormatXPS轉換成xps格式        object missing = Type.Missing;        Microsoft.Office.Interop.Word.applicationClass applicationClass = null;        Document document = null;        try        {            applicationClass = new Microsoft.Office.Interop.Word.ApplicationClass();            object inputfileName = sourcePath;//需要轉格式的文件路徑            string outputFileName = targetPath;//轉換完成后PDF或XPS文件的路徑和文件名名稱            WdExportFormat exportFormat = wdExportFormatPDF;//導出文件所使用的格式            bool openAfterExport = false;//轉換完成后是否打開            WdExportOptimizeFor wdExportOptimizeForPRint = WdExportOptimizeFor.wdExportOptimizeForPrint;//導出方式1.wdExportOptimizeForPrint針對打印進行導出,質量較高,生成的文件大小較大。2.wdExportOptimizeForOnScreen 針對屏幕顯示進行導出,質量較差,生成的文件大小較小。            WdExportRange wdExportAllDocument = WdExportRange.wdExportAllDocument;//導出全部內容(枚舉)            int from = 0;//起始頁碼            int to = 0;//結束頁碼            WdExportItem wdExportDocumentContent = WdExportItem.wdExportDocumentContent;//指定導出過程中是否只包含文本或包含文本的標記.1.wdExportDocumentContent:導出文件沒有標記,2.導出文件有標記            bool includeDocProps = true;//指定是否包含新導出的文件在文檔屬性            bool keepIRM = true;//            WdExportCreateBookmarks wdExportCreateWordBookmarks = WdExportCreateBookmarks.wdExportCreateWordBookmarks;//1.wdExportCreateNoBookmarks:不要在導出文件中創建書簽,2.wdExportCreateHeadingBookmarks:標題和文本框導出的文件中創建一個書簽,3.wdExportCreateWordBookmarks每個字的書簽,其中包括除包含頁眉和頁腳中的所有書簽導出的文件中創建一個書簽。            bool docStructureTags = true;            bool bitmapMissingFonts = true;            bool UseISO19005_1 = false;//生成的文檔是否符合 ISO 19005-1 (PDF/A)            document = applicationClass.Documents.Open(ref inputfileName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);            if (document != null)            {                document.ExportAsFixedFormat(outputFileName, exportFormat, openAfterExport, wdExportOptimizeForPrint, wdExportAllDocument, from, to, wdExportDocumentContent, includeDocProps, keepIRM, wdExportCreateWordBookmarks, docStructureTags, bitmapMissingFonts, UseISO19005_1, ref missing);            }            result = true;        }        catch        {            result = false;        }        finally

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 阿鲁科尔沁旗| 宁波市| 泸定县| 芜湖县| 秀山| 临安市| 梁平县| 阿巴嘎旗| 东安县| 阳曲县| 平昌县| 石台县| 萨迦县| 鄂伦春自治旗| 京山县| 罗江县| 华宁县| 隆德县| 海伦市| 迁西县| 辽阳市| 博乐市| 崇阳县| 迁西县| 吉安县| 庆元县| 远安县| 游戏| 绥江县| 天水市| 临沭县| 璧山县| 横山县| 广西| 奉贤区| 余江县| 新蔡县| 出国| 宁波市| 芜湖县| 昆山市|