如何把asp文件格式轉(zhuǎn)換成pdf文件格式?
ASP實現(xiàn)將WORD等文檔生成成pdf文檔方法如下: 一、添加引用 using Microsoft.Office.Interop.Word; 二、轉(zhuǎn)換方法 1、方法 C# 代碼 ///
///需要轉(zhuǎn)換的文件路徑和文件名稱 ///轉(zhuǎn)換完成后的文件的路徑和文件名名稱 /// public static bool WordToPdf(string sourcePath, string targetPath) { bool result = false; WdExportFormat wdExportFormatPDF = WdExportFormat.wdExportFormatPDF;//轉(zhuǎn)換格式 1.wdExportFormatPDF轉(zhuǎn)換成pdf格式 2.wdExportFormatXPS轉(zhuǎn)換成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;//需要轉(zhuǎn)格式的文件路徑 string outputFileName = targetPath;//轉(zhuǎn)換完成后PDF或XPS文件的路徑和文件名名稱 WdExportFormat exportFormat = wdExportFormatPDF;//導(dǎo)出文件所使用的格式 bool OpenAfterExport = false;//轉(zhuǎn)換完成后是否打開 WdExportOptimizeFor wdExportOptimizeForPrint = WdExportOptimizeFor.wdExportOptimizeForPrint;//導(dǎo)出方式1.wdExportOptimizeForPrint針對打印進 行導(dǎo)出,質(zhì)量較高,生成的文件大小較大。2.wdExportOptimizeForOnScreen 針對屏幕顯示進行導(dǎo)出, 質(zhì)量較差,生成的文件大小較小。 WdExportRange wdExportAllDocument = WdExportRange.wdExportAllDocument;//導(dǎo)出全 部內(nèi)容(枚舉) int from = 0;//起始頁碼 int to = 0;//結(jié)束頁碼 WdExportItem wdExportDocumentContent = WdExportItem.wdExportDocumentContent;// 指定導(dǎo)出過程中是否只包含文本或包含文本的標記.1.wdExportDocumentContent:導(dǎo)出文件沒有標記,2. 導(dǎo)出文件有標記 bool includeDocProps = true;//指定是否包含新導(dǎo)出的文件在文檔屬性 bool keepIRM = true;// WdExportCreateBookmarks wdExportCreateWordBookmarks = WdExportCreateBookmarks.wdExportCreateWordBookmarks; //1.wdExportCreateNoBookmarks:不要在導(dǎo)出文件中創(chuàng)建書簽 //2.wdExportCreateHeadingBookmarks:標題和文本框?qū)С龅奈募袆?chuàng)建一個書簽, //3.wdExportCreateWordBookmarks每個字的書簽,其中包括除包含頁眉和頁腳中的所有書簽導(dǎo)出的文件中創(chuàng)建一個書簽。 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; }