欧美一区2区三区4区公司二百,国产精品婷婷午夜在线观看,自拍偷拍亚洲精品,国产美女诱惑一区二区

C# 將word/ppt文檔轉(zhuǎn)換為Pdf的三種方法

? ? ? 利用office自帶的COM類型庫組件實(shí)現(xiàn)轉(zhuǎn)換Pdf功能。只要安裝了office的服務(wù)器上都可以調(diào)用,不需要額外的第三方組件,功能也更加豐富和強(qiáng)大,幾乎可以不受限制的操作office所有類型文件。缺點(diǎn)是部署問題多,發(fā)布到客戶服務(wù)器進(jìn)行調(diào)試的話問題很多。禁忌:1,開發(fā)的時(shí)候調(diào)用,不同office版本的COM組件,比如Microsoft.Office.Interop.Word是v14,那ppt、excel等組件都要統(tǒng)一版本,不然問題很多;2,部署的服務(wù)器上只能安裝一個(gè)版本的office,比如開發(fā)時(shí)調(diào)用的Office 2010,那部署的服務(wù)器就只能裝 office 2010,建議不要混裝各種版本來匹配組件型號(hào),最終會(huì)導(dǎo)致哪個(gè)都不能用;3,常見的故障問題和解決方法附錄在該節(jié)末尾。

(1)利用Microsoft.Office.Interop.Word實(shí)現(xiàn)word轉(zhuǎn)換pdf.

首先安裝office 2010或其他更高版本。

添加引用Microsoft.Office.Interop. Word:

C#代碼中添加引用:

using System.Text;

?

using Microsoft.Office.Interop.Word;

using WdExportFormat = Microsoft.Office.Interop.Word.WdExportFormat;

?

創(chuàng)建WordToPdf方法:

/// <summary>

??????? /// 把Word文件轉(zhuǎn)換成pdf文件

??????? /// </summary>

??????? /// <param name="sourcePath">需要轉(zhuǎn)換的文件路徑和文件名稱</param>

??????? /// <param name="targetPath">轉(zhuǎn)換完成后的文件的路徑和文件名名稱</param>

??????? /// <returns>成功返回true,失敗返回false</returns>

??????? public static bool WordToPdf(stringsourcePath, string targetPath)

??????? {

???????????

??????????? bool result = false;

??????????? Microsoft.Office.Interop.Word.WdExportFormatwdExportFormatPDF = Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF;//轉(zhuǎn)換格式1.wdExportFormatPDF轉(zhuǎn)換成pdf格式 2.wdExportFormatXPS轉(zhuǎn)換成xps格式

??????????? object missing = Type.Missing;

??????????? Microsoft.Office.Interop.Word.ApplicationClassapplicationClass = null;

??????????? Document document = null;

??????????? try

??????????? {

??????????????? applicationClass = newMicrosoft.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)換完成后是否打開

??????????????? WdExportOptimizeForwdExportOptimizeForPrint = WdExportOptimizeFor.wdExportOptimizeForPrint;//導(dǎo)出方式1.wdExportOptimizeForPrint針對(duì)打印進(jìn)行導(dǎo)出,質(zhì)量較高,生成的文件大小較大。2.wdExportOptimizeForOnScreen 針對(duì)屏幕顯示進(jìn)行導(dǎo)出,質(zhì)量較差,生成的文件大小較小。

??????????????? WdExportRange wdExportAllDocument = WdExportRange.wdExportAllDocument;//導(dǎo)出全部?jī)?nèi)容(枚舉)

??????????????? int from = 0;//起始頁碼

??????????????? int to = 0;//結(jié)束頁碼

??????????????? WdExportItemwdExportDocumentContent = WdExportItem.wdExportDocumentContent;//指定導(dǎo)出過程中是否只包含文本或包含文本的標(biāo)記.1.wdExportDocumentContent:導(dǎo)出文件沒有標(biāo)記,2.導(dǎo)出文件有標(biāo)記

??????????????? bool includeDocProps = true;//指定是否包含新導(dǎo)出的文件在文檔屬性

??????????????? bool keepIRM = true;//

??????????????? WdExportCreateBookmarkswdExportCreateWordBookmarks = WdExportCreateBookmarks.wdExportCreateWordBookmarks;//1.wdExportCreateNoBookmarks:不要在導(dǎo)出文件中創(chuàng)建書簽,2.wdExportCreateHeadingBookmarks:標(biāo)題和文本框?qū)С龅奈募袆?chuàng)建一個(gè)書簽,3.wdExportCreateWordBookmarks每個(gè)字的書簽,其中包括除包含頁眉和頁腳中的所有書簽導(dǎo)出的文件中創(chuàng)建一個(gè)書簽。

??????????????? bool docStructureTags = true;

??????????????? bool bitmapMissingFonts = true;

??????????????? bool UseISO19005_1 = false;//生成的文檔是否符合 ISO 19005-1 (PDF/A)

??????????????? document = applicationClass.Documents.Open(refinputfileName, ref missing, ref missing, refmissing, ref missing, ref missing, ref missing, refmissing, ref missing, ref missing, ref missing, refmissing, ref missing, ref missing, ref missing, refmissing);

??????????????? 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, refmissing, ref missing);

??????????????????? document = null;

??????????????? }

??????????????? if (applicationClass != null)

??????????????? {

???? ???????????????applicationClass.Quit(ref missing, ref missing, ref missing);

??????????????????? applicationClass = null;

??????????????? }

??????????? }

??????????? return result;

??????? }

調(diào)用該方法:

CommonCls.ConvertPdf.WordToPdf(sourcefilepath, targetfilepath);

(2)利用Microsoft.Office.Interop.PowerPoint實(shí)現(xiàn)ppt轉(zhuǎn)換pdf.

首先安裝office 2010或其他更高版本。

添加引用Microsoft.Office.Interop. PowerPoint:

?

?

?

?

?

?

(3)利用Microsoft.Office.Interop.*組件實(shí)現(xiàn)轉(zhuǎn)換pdf的常見問題和解決方法。

?? 未加載錯(cuò)誤

引用錯(cuò)誤

調(diào)試正常,發(fā)布到部署服務(wù)器時(shí)無法轉(zhuǎn)換

?

C# 將word/ppt文檔轉(zhuǎn)換為Pdf的三種方法

?

文章鏈接: http://m.qzkangyuan.com/11578.html

文章標(biāo)題:C# 將word/ppt文檔轉(zhuǎn)換為Pdf的三種方法

文章版權(quán):夢(mèng)飛科技所發(fā)布的內(nèi)容,部分為原創(chuàng)文章,轉(zhuǎn)載請(qǐng)注明來源,網(wǎng)絡(luò)轉(zhuǎn)載文章如有侵權(quán)請(qǐng)聯(lián)系我們!

聲明:本站所有文章,如無特殊說明或標(biāo)注,均為本站原創(chuàng)發(fā)布。任何個(gè)人或組織,在未征得本站同意時(shí),禁止復(fù)制、盜用、采集、發(fā)布本站內(nèi)容到任何網(wǎng)站、書籍等各類媒體平臺(tái)。如若本站內(nèi)容侵犯了原著者的合法權(quán)益,可聯(lián)系我們進(jìn)行處理。

給TA打賞
共{{data.count}}人
人已打賞
建站教程投稿分享

虛擬主機(jī)應(yīng)用場(chǎng)景

2022-10-24 15:28:48

建站教程投稿分享

DNS分離解析技術(shù)練習(xí)

2022-10-25 16:44:30

0 條回復(fù) A文章作者 M管理員
    暫無討論,說說你的看法吧
?
個(gè)人中心
購物車
優(yōu)惠劵
今日簽到
有新私信 私信列表
搜索
主站蜘蛛池模板: 远安县| 云南省| 荥经县| 福清市| 扎兰屯市| 黄大仙区| 六安市| 凉城县| 南澳县| 射洪县| 巫溪县| 洱源县| 桃江县| 华安县| 临城县| 凉城县| 娄底市| 津市市| 遵化市| 苍梧县| 连平县| 高尔夫| 唐河县| 石首市| 同仁县| 浦城县| 伊宁县| 兴国县| 金塔县| 台州市| 华容县| 大足县| 于田县| 太保市| 行唐县| 都匀市| 蓬溪县| 二连浩特市| 和林格尔县| 德惠市| 容城县|