以下是代码(我用的Chrome浏览器,无法添加程序块,面前看吧。代码是我正在用的,无错误,直接复制过来)
//ppt转pdf
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的引用