private void PPTAs(string infile, string outfile, PpSaveAsFileType targetFileType) { object missing = Type.Missing; Presentation persentation = null; PowerPoint.Application pptApp = null; try { pptApp = new PowerPoint.Application(); persentation = pptApp.Presentations.Open(infile, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse); persentation.SaveAs(outfile, targetFileType, Microsoft.Office.Core.MsoTriState.msoTrue); } catch (Exception ex) { log.ErrorFormat("PPT {0} 转换出错,异常信息: {1}", infile, ex.Message); } finally { if (persentation != null) { persentation.Close(); persentation = null; } if (pptApp != null) { pptApp.Quit(); pptApp = null; } } GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers(); }
protected override bool doConvertToPdf(string saveAsFile) { PpSaveAsFileType fileFormat = PpSaveAsFileType.ppSaveAsPDF; this.persentation.SaveAs(saveAsFile, fileFormat, MsoTriState.msoFalse); return(true); }
//将ppt文档转换成PDF格式 private bool FConvertPPT(string sourcePath, string targetPath //, PpSaveAsFileType targetFileType ) { PpSaveAsFileType targetFileType = PpSaveAsFileType.ppSaveAsPDF; bool result; object missing = Type.Missing; PowerPoint.ApplicationClass application = null; Presentation persentation = null; try { application = new PowerPoint.ApplicationClass(); persentation = application.Presentations.Open(sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse); persentation.SaveAs(targetPath, targetFileType, Microsoft.Office.Core.MsoTriState.msoTrue); result = true; } catch { result = false; } finally { if (persentation != null) { persentation.Close(); persentation = null; } if (application != null) { application.Quit(); application = null; } System.GC.Collect(); System.GC.WaitForPendingFinalizers(); System.GC.Collect(); System.GC.WaitForPendingFinalizers(); } return(result); }
/// <summary> /// PowerPoint格式转换(默认转成PDF) /// </summary> /// <param name="sourcePath">源路径</param> /// <param name="targetPath">目标路径</param> /// <param name="targetFileType">转换类型</param> /// <returns></returns> public static bool PowerPointConvert(string sourcePath, string targetPath, PpSaveAsFileType targetFileType = PpSaveAsFileType.ppSaveAsPDF) { Microsoft.Office.Interop.PowerPoint.ApplicationClass pptApplication = null; Presentation pptPersentation = null; try { pptApplication = new Microsoft.Office.Interop.PowerPoint.ApplicationClass(); pptPersentation = pptApplication.Presentations.Open(sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse); pptPersentation.SaveAs(targetPath, targetFileType, MsoTriState.msoTrue); } catch (Exception e) { Console.WriteLine(e.Message); throw; } finally { if (pptPersentation != null) { pptPersentation.Close(); } if (pptApplication != null) { int k; var t = new IntPtr(pptApplication.HWND); GetWindowThreadProcessId(t, out k); var p = System.Diagnostics.Process.GetProcessById(k); pptApplication.Quit(); p.Kill(); } GC.Collect(); GC.WaitForPendingFinalizers(); } return(true); }
public void SaveCopyAs(string FileName, PpSaveAsFileType FileFormat = PpSaveAsFileType.ppSaveAsDefault, Microsoft.Office.Core.MsoTriState EmbedTrueTypeFonts = Microsoft.Office.Core.MsoTriState.msoTriStateMixed) { throw new NotImplementedException(); }
public void PPT2Image(string infile, string outfile) { PpSaveAsFileType targetFileType = PpSaveAsFileType.ppSaveAsPNG; PPTAs(infile, outfile, targetFileType); }