title: Clean up powerpoint application without closing open instances
body: <p>I am trying to use powerpoint to headlessly convert .pptx files into pdfs.  Code below.  The problem is that if the user has powerpoint open for some other reason (like creating slides), and they use the functionality that calls this code, thier powerpoint app closes.</p>
  
  <p>How can I avoid this?  I have other ways to convert ppt files to pdf, but they are slower.  Idealy, I would use this method and not kill the running instance (but still clean up in the case where no instance is running).  Worst case, I would use the slower printing method if powerpoint is open.  I'm not sure how to do either.</p>
  
  <p>Code:</p>
  
  <pre><code>        private void ConvertPowerpointToPdf(string inputFile, string outputFile)
          {
              var powerPointApp = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
              Presentation presentation = null;
              Presentations presentations = null;
  
              try
              {
                  presentations = powerPointApp.Presentations;
                  presentation = presentations.Open(inputFile, ReadOnly: MsoTriState.msoFalse, WithWindow: MsoTriState.msoFalse, Untitled: MsoTriState.msoFalse);
  
                  presentation.ExportAsFixedFormat(outputFile, PpFixedFormatType.ppFixedFormatTypePDF,
                  PpFixedFormatIntent.ppFixedFormatIntentScreen, MsoTriState.msoFalse,
                  PpPrintHandoutOrder.ppPrintHandoutVerticalFirst, PpPrintOutputType.ppPrintOutputSlides,
                  MsoTriState.msoFalse, null, PpPrintRangeType.ppPrintAll, string.Empty, false, true, true, true, false,
                  Type.Missing);
              }
              finally
              {
  
                  if (presentation != null)
                  {
                      presentation.Close();
                      Release(presentation);
                  }
  
                  Release(presentations);
  
                  powerPointApp.Quit();
                  Release(powerPointApp);
              }
          }
  </code></pre>