您现在的位置是:网站首页> 编程资料编程资料
asp.net实现将ppt文档转换成pdf的方法_实用技巧_
2023-05-24
578人已围观
简介 asp.net实现将ppt文档转换成pdf的方法_实用技巧_
本文实例讲述了asp.net实现将ppt文档转换成pdf的方法。分享给大家供大家参考。具体实现方法如下:
一、添加引用
复制代码 代码如下:
using Microsoft.Office.Core;
using Microsoft.Office.Interop.PowerPoint;
using Microsoft.Office.Interop.PowerPoint;
二、转换方法
复制代码 代码如下:
///
/// 把PowerPoint文件转换成PDF格式文件
///
///源文件路径
///目标文件路径
///成功返回true,失败返回false
public static bool PPTConvertToPDF(string sourcePath, string targetPath)
{
bool result;
PpSaveAsFileType ppSaveAsFileType = PpSaveAsFileType.ppSaveAsPDF;//转换成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文件转换成PDF格式文件
///
///源文件路径
///目标文件路径
///
public static bool PPTConvertToPDF(string sourcePath, string targetPath)
{
bool result;
PpSaveAsFileType ppSaveAsFileType = PpSaveAsFileType.ppSaveAsPDF;//转换成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;
}
三、调用
复制代码 代码如下:
OfficeToPdf.PPTToPDF("d:\\12345.pptx", "d:\\12345.pdf");
希望本文所述对大家的asp.net程序设计有所帮助。
您可能感兴趣的文章:
相关内容
- ASP.NET中MVC使用AJAX调用JsonResult方法并返回自定义错误信息_实用技巧_
- C#中OpenFileDialog和PictrueBox的用法分析_实用技巧_
- ASP.Net页面生成饼图实例_实用技巧_
- asp.net中生成饼状与柱状图实例_实用技巧_
- Asp.Net实现404页面与301重定向的方法_实用技巧_
- asp.net检查服务器上目录或文件是否存在的方法_实用技巧_
- Asp.Net的FileUpload类实现上传文件实例_实用技巧_
- asp.net使用DataGridTree实现下拉树的方法_实用技巧_
- asp.net更新指定记录的方法_实用技巧_
- asp.net中CSharpThinking扩展方法分析_实用技巧_
