asp.net實(shí)現(xiàn)將ppt文檔轉(zhuǎn)換成pdf的方法
更新時(shí)間:2014年11月14日 10:21:26 投稿:shichen2014
這篇文章主要介紹了asp.net實(shí)現(xiàn)將ppt文檔轉(zhuǎn)換成pdf的方法,通過自定義函數(shù)實(shí)現(xiàn)將pptx格式的文件轉(zhuǎn)換成pdf格式文件的功能,是非常實(shí)用的技巧,需要的朋友可以參考下
本文實(shí)例講述了asp.net實(shí)現(xiàn)將ppt文檔轉(zhuǎn)換成pdf的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
一、添加引用
復(fù)制代碼 代碼如下:
using Microsoft.Office.Core;
using Microsoft.Office.Interop.PowerPoint;
using Microsoft.Office.Interop.PowerPoint;
二、轉(zhuǎn)換方法
復(fù)制代碼 代碼如下:
///<summary>
/// 把PowerPoint文件轉(zhuǎn)換成PDF格式文件
///</summary>
///<param name="sourcePath">源文件路徑</param>
///<param name="targetPath">目標(biāo)文件路徑</param>
///<returns>成功返回true,失敗返回false</returns>
public static bool PPTConvertToPDF(string sourcePath, string targetPath)
{
bool result;
PpSaveAsFileType ppSaveAsFileType = PpSaveAsFileType.ppSaveAsPDF;//轉(zhuǎn)換成pdf
object missing = Type.Missing;
Microsoft.Office.Interop.PowerPoint.ApplicationClass application = null;
Presentation persentation = null;
try
{
application = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
persentation = application.Presentations.Open(sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
if (persentation!=null)
{
persentation.SaveAs(targetPath, ppSaveAsFileType, MsoTriState.msoTrue);
}
result = true;
}
catch
{
result = false;
}
finally
{
if (persentation != null)
{
persentation.Close();
persentation = null;
}
if (application != null)
{
application.Quit();
application = null;
}
}
return result;
}
/// 把PowerPoint文件轉(zhuǎn)換成PDF格式文件
///</summary>
///<param name="sourcePath">源文件路徑</param>
///<param name="targetPath">目標(biāo)文件路徑</param>
///<returns>成功返回true,失敗返回false</returns>
public static bool PPTConvertToPDF(string sourcePath, string targetPath)
{
bool result;
PpSaveAsFileType ppSaveAsFileType = PpSaveAsFileType.ppSaveAsPDF;//轉(zhuǎn)換成pdf
object missing = Type.Missing;
Microsoft.Office.Interop.PowerPoint.ApplicationClass application = null;
Presentation persentation = null;
try
{
application = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
persentation = application.Presentations.Open(sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
if (persentation!=null)
{
persentation.SaveAs(targetPath, ppSaveAsFileType, MsoTriState.msoTrue);
}
result = true;
}
catch
{
result = false;
}
finally
{
if (persentation != null)
{
persentation.Close();
persentation = null;
}
if (application != null)
{
application.Quit();
application = null;
}
}
return result;
}
三、調(diào)用
復(fù)制代碼 代碼如下:
OfficeToPdf.PPTToPDF("d:\\12345.pptx", "d:\\12345.pdf");
希望本文所述對(duì)大家的asp.net程序設(shè)計(jì)有所幫助。
您可能感興趣的文章:
- C#實(shí)現(xiàn)pdf導(dǎo)出 .Net導(dǎo)出pdf文件
- ASP.NET實(shí)現(xiàn)將word文檔轉(zhuǎn)換成pdf的方法
- asp.net 按指定模板導(dǎo)出word,pdf實(shí)例代碼
- Asp.net實(shí)現(xiàn)直接在瀏覽器預(yù)覽Word、Excel、PDF、Txt文件(附源碼)
- ASP.NET MVC 項(xiàng)目直接預(yù)覽PDF文件
- 詳解開源免費(fèi)且穩(wěn)定實(shí)用的.NET PDF打印組件itextSharp(.NET組件介紹之八)
- ASP.NET保存PDF、Word和Excel文件到數(shù)據(jù)庫
- 如何使用Rotativa在ASP.NET Core MVC中創(chuàng)建PDF詳解
相關(guān)文章
手動(dòng)把a(bǔ)sp.net的類生成dll文件的方法
當(dāng)我們在開發(fā)的時(shí)候,有時(shí)會(huì)將一些方法封裝起來供別人調(diào)用,下面就是一種生成DLL的方法.2009-11-11
使用.NET Core實(shí)現(xiàn)餓了嗎拆紅包功能
這篇文章主要介紹了使用.NET Core實(shí)現(xiàn)餓了嗎拆紅包功能,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-07-07
ASP.NET Core 2.1 使用Docker運(yùn)行的方法步驟
這篇文章主要介紹了ASP.NET Core 2.1 使用Docker運(yùn)行的方法步驟,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-07-07
如何利用FluentMigrator實(shí)現(xiàn)數(shù)據(jù)庫遷移
這篇文章主要給大家介紹了關(guān)于如何利用FluentMigrator實(shí)現(xiàn)數(shù)據(jù)庫遷移的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04
asp.net異步獲取datatable并顯示的實(shí)現(xiàn)方法
這篇文章主要介紹了asp.net異步獲取datatable并顯示的實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了asp.net一步操作datatable的相關(guān)技巧,需要的朋友可以參考下2016-03-03

