好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > ASP.NET實現將word文檔轉換成pdf的方法

ASP.NET實現將word文檔轉換成pdf的方法

熱門標簽:征途美甲店地圖標注 柳州電銷機器人公司 騰訊地圖標注手機 太原400電話上門辦理 昆明語音電銷機器人價格 400電話如何申請取消 電銷語音機器人型號參數 浦發電話機器人提醒還款 百度地圖怎樣做地圖標注

本文實例講述了ASP.NET實現將word文檔轉換成pdf的方法,分享給大家供大家參考。具體實現步驟如下:

一、添加引用

復制代碼 代碼如下:
using Microsoft.Office.Interop.Word;

 
二、轉換方法
 
1、方法

復制代碼 代碼如下:
/// 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
        {
            if (document != null)
            {
                document.Close(ref missing, ref missing, ref missing);
                document = null;
            }
            if (applicationClass != null)
            {
                applicationClass.Quit(ref missing, ref missing, ref missing);
                applicationClass = null;
            }
        }
        return result;
    }

 
2、簡潔方法

復制代碼 代碼如下:
/// summary>
    /// 把Word文件轉換成pdf文件
    /// /summary>
    /// param name="sourcePath">需要轉換的文件路徑和文件名稱/param>
    /// param name="targetPath">轉換完成后的文件的路徑和文件名名稱/param>
    /// returns>成功返回true,失敗返回false/returns>
    public static bool WordToPdf(object sourcePath, string targetPath)
    {
        bool result = false;
        WdExportFormat wdExportFormatPDF = WdExportFormat.wdExportFormatPDF;
        object missing = Type.Missing;
        Microsoft.Office.Interop.Word.ApplicationClass applicationClass = null;
        Document document = null;
        try
        {
            applicationClass = new Microsoft.Office.Interop.Word.ApplicationClass();
            document = applicationClass.Documents.Open(ref sourcePath, 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(targetPath, wdExportFormatPDF, false, WdExportOptimizeFor.wdExportOptimizeForPrint, WdExportRange.wdExportAllDocument, 0, 0, WdExportItem.wdExportDocumentContent, true, true, WdExportCreateBookmarks.wdExportCreateWordBookmarks, true, true, false, ref missing);
            }
            result = true;
        }
        catch
        {
            result = false;
        }
        finally
        {
            if (document != null)
            {
                document.Close(ref missing, ref missing, ref missing);
                document = null;
            }
            if (applicationClass != null)
            {
                applicationClass.Quit(ref missing, ref missing, ref missing);
                applicationClass = null;
            }
        }
        return result;
    }

 
三、調用
復制代碼 代碼如下:
OfficeToPdf.WordToPdf("d:\\1234.doc", "d:\\1234.pdf");

希望本文所述對大家的asp.net程序設計有所幫助。

您可能感興趣的文章:
  • C#實現pdf導出 .Net導出pdf文件
  • asp.net 按指定模板導出word,pdf實例代碼
  • Asp.net實現直接在瀏覽器預覽Word、Excel、PDF、Txt文件(附源碼)
  • ASP.NET MVC 項目直接預覽PDF文件
  • 詳解開源免費且穩定實用的.NET PDF打印組件itextSharp(.NET組件介紹之八)
  • asp.net實現將ppt文檔轉換成pdf的方法
  • ASP.NET保存PDF、Word和Excel文件到數據庫
  • 如何使用Rotativa在ASP.NET Core MVC中創建PDF詳解

標簽:陽泉 新疆 江蘇 張家界 天門 德陽 白山 蘭州

巨人網絡通訊聲明:本文標題《ASP.NET實現將word文檔轉換成pdf的方法》,本文關鍵詞  ASP.NET,實,現將,word,文檔,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《ASP.NET實現將word文檔轉換成pdf的方法》相關的同類信息!
  • 本頁收集關于ASP.NET實現將word文檔轉換成pdf的方法的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 国产精品女A片爽视频爽| 欧美精品综合| 网纸线观看无码精品秘?日本| 鲁一鲁色一色| 脱光干x网| 欧美做爰XXXⅩ高潮69苍井空| 免费??成人??用黄上黄两年半| 小荡货好紧好浪fu| 《色欲迷墙》完整版在线观看 | 可脱身服全去掉的游戏在线玩| 欧洲性网| 黄色a级毛片| 双腿打开揉弄高潮?动漫表情包| 高清欧美精品XXXXX大豆行情| 农民影视免费观看vip电视剧免费| 96免费精品视频在线| 拉丁舞跳着跳着做起来了| 国产精品第九页| 亚洲国产精品99| 国产97在线亚洲| 特级淫片日本高清视频| 欧洲美女a视频一级毛片| 日本天堂视频| 69久久精品无码一区二区按摩 | videofree日本护士18hd| 少妇婬乱高潮AAAA片东京热| 欧美丰满少妇乱码Av | 宫女淫春3在线观| 草莓视频app18禁下载安装| 91video国产一区| 亚洲初脱人体无圣光| 老师脱??让学生摸??| 国产精品久久久久久久精品贰摆| 国外欧美一区另类中文字幕| 疯狂的撞击她的娇嫩h| 92看片淫黄大片一级| 无码人妻精品一区二区三区千菊 | 国产三级在线精品男人的天堂 | 毛片在哪里看| 中文字幕精品免费免费| 老师好大好爽我要喷水了np|