ppt-->PDF
下载并安装SaveAsPDF.exe
需要安装Office 2007和Microsoft提供的“Microsoft Save as PDF or XPS Add-in for 2007 Microsoft Office programs”组件,可以从官网下载。
以下是代码(我用的Chrome浏览器,无法添加程序块,面前看吧。代码是我正在用的,无错误,直接复制过来)
//ppt转pdf
以下是代码(我用的Chrome浏览器,无法添加程序块,面前看吧。代码是我正在用的,无错误,直接复制过来)
//ppt转pdf
using Microsoft.Office.Interop.PowerPoint;
using Microsoft.Office.core;
protected void PPTToPDF(string fileNameDateTime, string fileNameDateTimeWithoutExtension)
{
string paramSource = Server.MapPath("~/materials/internalPDF/") + fileNameDateTime;
string paramTarget = Server.MapPath("~/materials/internalPDF/") + fileNameDateTimeWithoutExtension + ".pdf";
Microsoft.Office.Interop.PowerPoint.ApplicationClass application = null;
Microsoft.Office.Interop.PowerPoint.Presentation presentation = null;
try
{
application = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
presentation = application.Presentations.Open(paramSource, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
presentation.SaveAs(paramTarget, PpSaveAsFileType.ppSaveAsPDF, MsoTriState.msoTrue);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
if (presentation != null)
{
presentation.Close();
presentation = null;
}
if (application != null)
{
application.Quit();
application = null;
}
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
注意添加对Microsoft.Office.Interop.PowerPoint的引用
protected void PPTToPDF(string fileNameDateTime, string fileNameDateTimeWithoutExtension)
{
string paramSource = Server.MapPath("~/materials/internalPDF/") + fileNameDateTime;
string paramTarget = Server.MapPath("~/materials/internalPDF/") + fileNameDateTimeWithoutExtension + ".pdf";
Microsoft.Office.Interop.PowerPoint.ApplicationClass application = null;
Microsoft.Office.Interop.PowerPoint.Presentation presentation = null;
try
{
application = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
presentation = application.Presentations.Open(paramSource, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
presentation.SaveAs(paramTarget, PpSaveAsFileType.ppSaveAsPDF, MsoTriState.msoTrue);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
if (presentation != null)
{
presentation.Close();
presentation = null;
}
if (application != null)
{
application.Quit();
application = null;
}
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
注意添加对Microsoft.Office.Interop.PowerPoint的引用