public override void Convert(String inputFile, String outputFile) { try { if (!File.Exists(inputFile)) { throw new ConvertException("File not Exists"); } if (IsPasswordProtected(inputFile)) { throw new ConvertException("Password Exist"); } app = new PowerPoint.Application(); presentations = app.Presentations; presentation = presentations.Open(inputFile, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse); presentation.ExportAsFixedFormat(outputFile, PowerPoint.PpFixedFormatType.ppFixedFormatTypePDF); // presentation.ExportAsFixedFormat(outputFile, PowerPoint.PpFixedFormatType.ppFixedFormatTypePDF, PowerPoint.PpFixedFormatIntent.ppFixedFormatIntentScreen, MsoTriState.msoFalse, PowerPoint.PpPrintHandoutOrder.ppPrintHandoutVerticalFirst, PowerPoint.PpPrintOutputType.ppPrintOutputSlides, MsoTriState.msoFalse, null, PowerPoint.PpPrintRangeType.ppPrintAll, "", false, false, false, false, false, null); } catch (Exception e) { release(); throw new ConvertException(e.Message); } release(); }
/// <summary> /// Convert pptx to PDF/XPS (install office PDF/XPS addin) /// </summary> private static void ConvertPPTXtoFixed(string source, string target, PpFixedFormatType fixedFormatType) { Microsoft.Office.Interop.PowerPoint.Application ppApp = new Microsoft.Office.Interop.PowerPoint.Application(); Microsoft.Office.Interop.PowerPoint.Presentation presentation = ppApp.Presentations.Open(source, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse); presentation.ExportAsFixedFormat(target, fixedFormatType, PpFixedFormatIntent.ppFixedFormatIntentPrint, Microsoft.Office.Core.MsoTriState.msoFalse, PpPrintHandoutOrder.ppPrintHandoutHorizontalFirst, PpPrintOutputType.ppPrintOutputSlides, Microsoft.Office.Core.MsoTriState.msoFalse, null, PpPrintRangeType.ppPrintAll, "", false, false, false, true, true, System.Reflection.Missing.Value); presentation.Close(); presentation = null; ppApp = null; GC.Collect(); }
/// <summary> /// Converts a PowerPoint document to PDF /// </summary> /// <param name="inputFile">The PowerPoint input file</param> /// <param name="outputFile">The PDF output file</param> /// <returns></returns> internal void Convert(string inputFile, string outputFile) { DeleteResiliencyKeys(); PowerPointInterop.Presentation presentation = null; try { StartPowerPoint(); presentation = OpenPresentation(inputFile, false); Logger.WriteToLog($"Exporting presentation to PDF file '{outputFile}'"); presentation.ExportAsFixedFormat(outputFile, PowerPointInterop.PpFixedFormatType.ppFixedFormatTypePDF); Logger.WriteToLog("Presentation exported to PDF"); } catch (Exception) { StopPowerPoint(); throw; } finally { ClosePresentation(presentation); } }
/// <summary> /// Methode qui transforme les fichiers PPT /// </summary> /// <param FileNoExtension="filePath"></param> /// <param FileNoExtension="fileName"></param> private void TraitementPPT(string fileName) { //Convertion du PPT ou PPTX en PDF try { Microsoft.Office.Interop.PowerPoint.Application ppApp = new Microsoft.Office.Interop.PowerPoint.Application(); Microsoft.Office.Interop.PowerPoint.Presentation presentation = ppApp.Presentations.Open(folderDoc + fileName, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse); string fileToConvert = foldertmp + string.Format("{0}.pdf", Path.GetFileNameWithoutExtension(fileName)); //Export du fichier sous format pdf dans tmp if (!File.Exists(fileToConvert)) { presentation.ExportAsFixedFormat(fileToConvert, PpFixedFormatType.ppFixedFormatTypePDF, PpFixedFormatIntent.ppFixedFormatIntentPrint, Microsoft.Office.Core.MsoTriState.msoFalse, PpPrintHandoutOrder.ppPrintHandoutHorizontalFirst, PpPrintOutputType.ppPrintOutputSlides, Microsoft.Office.Core.MsoTriState.msoFalse, null, PpPrintRangeType.ppPrintAll, "", false, true, true, true, false, System.Reflection.Missing.Value); } //Ouverture du nouveau PDF généré à partir du PPT ou PPTX TraitementPDF(foldertmp + string.Format("{0}.pdf", Path.GetFileNameWithoutExtension(fileName))); presentation.Close(); presentation = null; ppApp = null; GC.Collect(); } catch (Exception e) { MessageBox.Show(e.ToString()); } }
/// <summary> /// Converts a PowerPoint document to PDF /// </summary> /// <param name="inputFile">The PowerPoint input file</param> /// <param name="outputFile">The PDF output file</param> /// <returns></returns> internal static void Convert(string inputFile, string outputFile) { DeleteAutoRecoveryFiles(); PowerPointInterop.ApplicationClass powerPoint = null; PowerPointInterop.Presentation presentation = null; try { powerPoint = new PowerPointInterop.ApplicationClass { DisplayAlerts = PowerPointInterop.PpAlertLevel.ppAlertsNone, DisplayDocumentInformationPanel = false, AutomationSecurity = MsoAutomationSecurity.msoAutomationSecurityForceDisable }; presentation = Open(powerPoint, inputFile, false); presentation.ExportAsFixedFormat(outputFile, PowerPointInterop.PpFixedFormatType.ppFixedFormatTypePDF); } finally { if (presentation != null) { presentation.Saved = MsoTriState.msoFalse; presentation.Close(); Marshal.ReleaseComObject(presentation); } if (powerPoint != null) { powerPoint.Quit(); Marshal.ReleaseComObject(powerPoint); } } }
public void ExportToPDF(FileInfo file) { // Create COM Objects PowerPoint.Application pptApplication = null; PowerPoint.Presentation pptPresentation = null; try { object unknownType = Type.Missing; //start power point pptApplication = new PowerPoint.Application(); //open powerpoint document pptPresentation = pptApplication.Presentations.Open(file.FullName, MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoFalse); // save PowerPoint as PDF FileInfo newname = new FileInfo(file.FullName.Replace(".pptx", ".pdf")); pptPresentation.ExportAsFixedFormat(newname.FullName, PowerPoint.PpFixedFormatType.ppFixedFormatTypePDF, PowerPoint.PpFixedFormatIntent.ppFixedFormatIntentPrint, MsoTriState.msoFalse, PowerPoint.PpPrintHandoutOrder.ppPrintHandoutVerticalFirst, PowerPoint.PpPrintOutputType.ppPrintOutputSlides, MsoTriState.msoFalse, null, PowerPoint.PpPrintRangeType.ppPrintAll, string.Empty, true, true, true, true, false, unknownType); } catch (Exception error) { #if DEBUG Logger.Logger.Debug(error.Message); #else Logger.Log.Error(error.Message); #endif } finally { // Close and release the Document object. if (pptPresentation != null) { pptPresentation.Close(); } // Quit PowerPoint and release the ApplicationClass object. if (pptApplication != null) { pptApplication.Quit(); } } }
public void Parse(object src, object dest) { if (src == null || string.IsNullOrEmpty(src.ToString())) { throw new ArgumentNullException("源文件不能为空"); } if (dest == null || string.IsNullOrEmpty(dest.ToString())) { throw new ArgumentNullException("目标路径不能为空"); } try { presentation = pptApp.Presentations.Open(src.ToString(), Microsoft.Office.Core.MsoTriState.msoTrue , Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse); presentation.ExportAsFixedFormat(dest.ToString(), PpFixedFormatType.ppFixedFormatTypePDF, PpFixedFormatIntent.ppFixedFormatIntentScreen , Microsoft.Office.Core.MsoTriState.msoFalse, PpPrintHandoutOrder.ppPrintHandoutHorizontalFirst, PpPrintOutputType.ppPrintOutputSlides , Microsoft.Office.Core.MsoTriState.msoFalse, null, PpPrintRangeType.ppPrintAll, string.Empty, false , false, false, true, true, missing); } catch (Exception ex) { throw ex; } finally { if (presentation != null) { presentation.Close(); presentation = null; } if (pptApp != null) { pptApp.Quit(); pptApp = null; } GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers(); } }
public static void ConvertPowerPointDocumentToPdf(string srcFile, string dstFile) { PowerPoint.Application powerPointApp = null; PowerPoint.Presentation powerPointPresentation = null; try { powerPointApp = new PowerPoint.Application(); powerPointPresentation = powerPointApp.Presentations.Open(srcFile, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse); powerPointPresentation.ExportAsFixedFormat(dstFile, PowerPoint.PpFixedFormatType.ppFixedFormatTypePDF); } finally { powerPointPresentation?.Close(); powerPointApp?.Quit(); } }
public override void Convert(String inputFile, String outputFile) { try { if (!File.Exists(inputFile)) { throw new ConvertException("File not Exists"); } app = new PowerPoint.Application(); presentation = app.Presentations.Open(inputFile, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse); presentation.ExportAsFixedFormat(outputFile, PowerPoint.PpFixedFormatType.ppFixedFormatTypePDF); } catch (Exception e) { throw new ConvertException(e.Message); } finally { Release(); } }
/// <summary> /// 转换为pdf文件,适合(.ppt、pptx文件类型) /// </summary> /// <param name="fileName"></param> /// <param name="outputFileName"></param> /// <returns></returns> private static bool PowerPointExportAsPdf(string fileName, string outputFileName) { bool isSucceed = false; PowerPoint.PpFixedFormatType fileFormat = PowerPoint.PpFixedFormatType.ppFixedFormatTypePDF; PowerPoint.Application pptxApp = null; if (pptxApp == null) { pptxApp = new PowerPoint.Application(); } PowerPoint.Presentation presentation = null; try { presentation = pptxApp.Presentations.Open(fileName, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse); presentation.ExportAsFixedFormat(outputFileName, fileFormat); isSucceed = true; } finally { if (presentation != null) { presentation.Close(); presentation = null; } if (pptxApp != null) { pptxApp.Quit(); pptxApp = null; } GC.Collect(); GC.WaitForPendingFinalizers(); } return(isSucceed); }
public override void Convert(string inputFile, string outputFile) { if (!File.Exists(inputFile)) { throw new ConvertException("文件不存在!"); } try { // 打开文档 PowerPoint.Presentation ppt = _ppts.Open(inputFile, WithWindow: Microsoft.Office.Core.MsoTriState.msoFalse); // 转换文档 ppt.ExportAsFixedFormat(outputFile, PowerPoint.PpFixedFormatType.ppFixedFormatTypePDF); // 关闭文档 Close(ppt); } catch (Exception e) { // 打开、转换文档失败 throw new ConvertException(e); } }
public void ToPdf() { bool occupy = true; while (occupy) { try { using (File.Open(m_FilePathPowerPoint, FileMode.Open, FileAccess.ReadWrite, FileShare.None)) { } occupy = false;//如果可以运行至此那么就是 } catch (IOException e) { e.ToString(); Thread.Sleep(100); } } PPT.Application pptApp = null; PPT.Presentation presentation = null; try { pptApp = new PPT.Application(); presentation = pptApp.Presentations.Open(m_FilePathPowerPoint, Microsoft.Office.Core.MsoTriState.msoCTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse); string strPdf = m_FilePathPowerPoint.Substring(0, m_FilePathPowerPoint.LastIndexOf('.')) + ".pdf"; if (presentation != null) { presentation.ExportAsFixedFormat(strPdf, PPT.PpFixedFormatType.ppFixedFormatTypePDF, PPT.PpFixedFormatIntent.ppFixedFormatIntentPrint, CORE.MsoTriState.msoFalse, PPT.PpPrintHandoutOrder.ppPrintHandoutVerticalFirst, PPT.PpPrintOutputType.ppPrintOutputSlides, Microsoft.Office.Core.MsoTriState.msoFalse, null, PPT.PpPrintRangeType.ppPrintAll, "", false, false, false, true, true, System.Reflection.Missing.Value); } if (presentation != null) { presentation.Close(); System.Runtime.InteropServices.Marshal.ReleaseComObject(presentation); } if (pptApp != null) { pptApp.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(pptApp); } PostHttpMsg pm = new PostHttpMsg(); pm.DataPost = strPdf; pm.PostMsg(); } catch (System.Exception e) { e.ToString(); } finally { presentation = null; pptApp = null; GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers(); } }
public static new int Convert(String inputFile, String outputFile, Hashtable options, ref List <PDFBookmark> bookmarks) { // Check for password protection if (Converter.IsPasswordProtected(inputFile)) { Console.WriteLine("Unable to open password protected file"); return((int)ExitCode.PasswordFailure); } Boolean running = (Boolean)options["noquit"]; try { Microsoft.Office.Interop.PowerPoint.Application app = null; Microsoft.Office.Interop.PowerPoint.Presentation activePresentation = null; Microsoft.Office.Interop.PowerPoint.Presentations presentations = null; try { try { app = (Microsoft.Office.Interop.PowerPoint.Application)Marshal.GetActiveObject("PowerPoint.Application"); } catch (System.Exception) { int tries = 10; app = new Microsoft.Office.Interop.PowerPoint.Application(); running = false; while (tries > 0) { try { // Try to set a property on the object app.DisplayAlerts = PpAlertLevel.ppAlertsNone; } catch (COMException) { // Decrement the number of tries and have a bit of a snooze tries--; Thread.Sleep(500); continue; } // Looks ok, so bail out of the loop break; } if (tries == 0) { Converter.releaseCOMObject(app); return((int)ExitCode.ApplicationError); } } MSCore.MsoTriState nowrite = (Boolean)options["readonly"] ? MSCore.MsoTriState.msoTrue : MSCore.MsoTriState.msoFalse; bool pdfa = (Boolean)options["pdfa"] ? true : false; if ((Boolean)options["hidden"]) { // Can't really hide the window, so at least minimise it app.WindowState = PpWindowState.ppWindowMinimized; } PpFixedFormatIntent quality = PpFixedFormatIntent.ppFixedFormatIntentScreen; if ((Boolean)options["print"]) { quality = PpFixedFormatIntent.ppFixedFormatIntentPrint; } if ((Boolean)options["screen"]) { quality = PpFixedFormatIntent.ppFixedFormatIntentScreen; } Boolean includeProps = !(Boolean)options["excludeprops"]; Boolean includeTags = !(Boolean)options["excludetags"]; app.FeatureInstall = MSCore.MsoFeatureInstall.msoFeatureInstallNone; app.DisplayDocumentInformationPanel = false; app.DisplayAlerts = PpAlertLevel.ppAlertsNone; app.Visible = MSCore.MsoTriState.msoTrue; app.AutomationSecurity = MSCore.MsoAutomationSecurity.msoAutomationSecurityLow; presentations = app.Presentations; activePresentation = presentations.Open2007(inputFile, nowrite, MSCore.MsoTriState.msoTrue, MSCore.MsoTriState.msoTrue, MSCore.MsoTriState.msoTrue); activePresentation.Final = false; // Sometimes, presentations can have restrictions on them that block // access to the object model (e.g. fonts containing restrictions). // If we attempt to access the object model and fail, then try a more // sneaky method of getting the presentation - create an empty presentation // and insert the slides from the original file. var fonts = activePresentation.Fonts; try { var fontCount = fonts.Count; } catch (System.Runtime.InteropServices.COMException) { Converter.releaseCOMObject(fonts); // This presentation looked read-only activePresentation.Close(); Converter.releaseCOMObject(activePresentation); // Create a new blank presentation and insert slides from the original activePresentation = presentations.Add(MSCore.MsoTriState.msoFalse); // This is only a band-aid - backgrounds won't come through activePresentation.Slides.InsertFromFile(inputFile, 0); } Converter.releaseCOMObject(fonts); activePresentation.ExportAsFixedFormat(outputFile, PpFixedFormatType.ppFixedFormatTypePDF, quality, MSCore.MsoTriState.msoFalse, PpPrintHandoutOrder.ppPrintHandoutVerticalFirst, PpPrintOutputType.ppPrintOutputSlides, MSCore.MsoTriState.msoFalse, null, PpPrintRangeType.ppPrintAll, "", includeProps, true, includeTags, true, pdfa, Type.Missing); // Determine if we need to make bookmarks if ((bool)options["bookmarks"]) { loadBookmarks(activePresentation, ref bookmarks); } activePresentation.Saved = MSCore.MsoTriState.msoTrue; activePresentation.Close(); return((int)ExitCode.Success); } catch (Exception e) { Console.WriteLine(e.Message); return((int)ExitCode.UnknownError); } finally { Converter.releaseCOMObject(activePresentation); Converter.releaseCOMObject(presentations); if (app != null && !running) { app.Quit(); } Converter.releaseCOMObject(app); GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers(); } } catch (System.Runtime.InteropServices.COMException e) { Console.WriteLine(e.Message); return((int)ExitCode.UnknownError); } }
private int convertPowerp2pdf(List <string> pwr, string dirsal) { PowerPoint.Application pptApplication = null; PowerPoint.Presentation pptPresentation = null; object unknownType = Type.Missing; try { //Abrir aplicacion de PowerPoint pptApplication = new PowerPoint.Application(); } catch (Exception exect) { } int code = 0; for (int i = 0; i < pwr.Count; i++) { string entrada = pwr[i]; consola.escribir("Convirtiendo: " + entrada, true); string archSalida = Path.GetFileNameWithoutExtension(pwr[i]) + ".pdf"; string salida = Path.Combine(dirsal, archSalida); try { //abrir el docuemento de PowerPoint pptPresentation = pptApplication.Presentations.Open(entrada, MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoFalse); //exportar documento a PDF if (pptPresentation != null) { pptPresentation.ExportAsFixedFormat(salida, PowerPoint.PpFixedFormatType.ppFixedFormatTypePDF, PowerPoint.PpFixedFormatIntent.ppFixedFormatIntentPrint, MsoTriState.msoFalse, PowerPoint.PpPrintHandoutOrder.ppPrintHandoutVerticalFirst, PowerPoint.PpPrintOutputType.ppPrintOutputSlides, MsoTriState.msoFalse, null, PowerPoint.PpPrintRangeType.ppPrintAll, string.Empty, true, true, true, true, false, unknownType); consola.escribir("OK", false); consola.salto(); code += 1; } else { consola.escribir(" fallo", false); consola.salto(); } } catch (Exception exPowerPoint2Pdf) { consola.escribir(" fallo", false); consola.salto(); } finally { // cerrar y liberar documento if (pptPresentation != null) { try { pptPresentation.Close(); } catch (Exception dedsa) { } funcionesVarias.liberarObjet(pptPresentation); pptPresentation = null; } } } try { // cerrar aplicacion y liberar objeto que lo representa pptApplication.Quit(); funcionesVarias.liberarObjet(pptApplication); pptApplication = null; } catch (Exception ex) { } return(code); }
private static OfficeToXpsConversionResult ConvertFromPowerPoint(string sourceFilePath, ref string resultFilePath) { string pSourceDocPath = sourceFilePath; string pExportFilePath = string.IsNullOrWhiteSpace(resultFilePath) ? GetTempXpsFilePath() : resultFilePath; try { PowerPoint.Application pptApplication = null; PowerPoint.Presentation pptPresentation = null; try { pptApplication = new PowerPoint.Application(); } catch (Exception exc) { return(new OfficeToXpsConversionResult(ConversionResult.ErrorUnableToInitializeOfficeApp, exc.Message, exc)); } try { try { pptPresentation = pptApplication.Presentations.Open(pSourceDocPath, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse); } catch (Exception exc) { return(new OfficeToXpsConversionResult(ConversionResult.ErrorUnableToOpenOfficeFile, exc.Message, exc)); } if (pptPresentation != null) { try { pptPresentation.ExportAsFixedFormat( pExportFilePath, PowerPoint.PpFixedFormatType.ppFixedFormatTypeXPS, PowerPoint.PpFixedFormatIntent.ppFixedFormatIntentScreen, Microsoft.Office.Core.MsoTriState.msoFalse, PowerPoint.PpPrintHandoutOrder.ppPrintHandoutVerticalFirst, PowerPoint.PpPrintOutputType.ppPrintOutputSlides, Microsoft.Office.Core.MsoTriState.msoFalse, null, PowerPoint.PpPrintRangeType.ppPrintAll, string.Empty, true, true, true, true, false ); } catch (Exception exc) { return(new OfficeToXpsConversionResult(ConversionResult.ErrorUnableToExportToXps, exc.Message, exc)); } } else { return(new OfficeToXpsConversionResult(ConversionResult.ErrorUnableToOpenOfficeFile)); } } finally { // Close and release the Document object. if (pptPresentation != null) { pptPresentation.Close(); pptPresentation = null; } // Quit Word and release the ApplicationClass object. if (pptApplication != null) { pptApplication.Quit(); pptApplication = null; } GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers(); } } catch (Exception exc) { return(new OfficeToXpsConversionResult(ConversionResult.ErrorUnableToAccessOfficeInterop, exc.Message, exc)); } resultFilePath = pExportFilePath; return(new OfficeToXpsConversionResult(ConversionResult.OK, pExportFilePath)); }
static void Main(string[] args) { CommandLineArguments cmdLineArgs = ParseCommandLineArgs(args); // If the cmdLineArgs are null, print out help if (cmdLineArgs == null) { Console.WriteLine(); PrintHelp(); return; } // Create the output dir if it doesn't exist if (!Directory.Exists(cmdLineArgs.OutputDir)) { Directory.CreateDirectory(cmdLineArgs.OutputDir); } Console.WriteLine("The input directory: {0}", cmdLineArgs.InputDir); Console.WriteLine("The output directory: {0}", cmdLineArgs.OutputDir); // Process and save PowerPoint thumbnails int pptIndex = 1; string[] pptFilesWithPath = Directory.GetFiles(cmdLineArgs.InputDir, "*.ppt*", SearchOption.AllDirectories); Console.WriteLine("Found {0} PowerPoint files", pptFilesWithPath.Length); var watch = System.Diagnostics.Stopwatch.StartNew(); foreach (string pptFileNameWithPath in pptFilesWithPath) { string pptFileName = Path.GetFileName(pptFileNameWithPath); string pptPath = Path.GetDirectoryName(pptFileNameWithPath); string justFilenameNoExt = Path.GetFileNameWithoutExtension(pptFileNameWithPath); string pdfFilename = justFilenameNoExt + ".pdf"; string pdfFilenameWithPath = Path.Combine(cmdLineArgs.OutputDir, pdfFilename); if (!cmdLineArgs.OverwriteFiles) { pdfFilenameWithPath = GetUniqueFilename(pdfFilenameWithPath); } // The following PPT -> PDF conversion code is based on: // http://stackoverflow.com/questions/32582433/converting-powerpoint-presentations-ppt-x-to-pdf-without-interop // Create COM Objects PowerPoint.Application pptApplication = null; PowerPoint.Presentation pptPresentation = null; try { object unknownType = Type.Missing; //start power point //TODO: for efficiency, could create this object once rather //then everytime through the loop. Would have to change pptApplication.Quit() stuff //below as well. This runs fine though, so not going to change it for now. pptApplication = new PowerPoint.Application(); //open powerpoint document pptPresentation = pptApplication.Presentations.Open(pptFileNameWithPath, MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoFalse); // save PowerPoint as PDF pptPresentation.ExportAsFixedFormat(pdfFilenameWithPath, PowerPoint.PpFixedFormatType.ppFixedFormatTypePDF, PowerPoint.PpFixedFormatIntent.ppFixedFormatIntentPrint, MsoTriState.msoFalse, PowerPoint.PpPrintHandoutOrder.ppPrintHandoutVerticalFirst, PowerPoint.PpPrintOutputType.ppPrintOutputSlides, MsoTriState.msoFalse, null, PowerPoint.PpPrintRangeType.ppPrintAll, string.Empty, true, true, true, true, false, unknownType); } finally { // Close and release the Document object. if (pptPresentation != null) { pptPresentation.Close(); pptPresentation = null; } // Quit PowerPoint and release the ApplicationClass object. if (pptApplication != null) { pptApplication.Quit(); pptApplication = null; } } } watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; Console.WriteLine("Processed {0} PowerPoint files in {1} ms", pptFilesWithPath.Length, elapsedMs); Console.WriteLine("Press any key to continue"); Console.ReadLine(); }