0
votes

We are trying to convert PPT file to PDF using Powerpoint Office Interop. We are using ExportAsFixedFormat() to do the conversion as shown in the below code snippet:

        public static void ConvertPowerPointToPdf(string inputFile)
        {
            string outputFileName = @"C:\All format files\PPT2PDF.pdf";

            Microsoft.Office.Interop.PowerPoint.Application powerPointApp =
            new Microsoft.Office.Interop.PowerPoint.Application();
            Presentation presentation = null;
            Presentations presentations = null;
            try
            {
                presentations = powerPointApp.Presentations;
                presentation = presentations.Open(inputFile, MsoTriState.msoFalse, MsoTriState.msoFalse,
                MsoTriState.msoFalse);

                presentation.PageSetup.SlideSize = PpSlideSizeType.ppSlideSizeA4Paper; //It throws the exception here

                presentation.ExportAsFixedFormat(outputFileName, PpFixedFormatType.ppFixedFormatTypePDF,
                PpFixedFormatIntent.ppFixedFormatIntentPrint);
            }
            catch (Exception)
            {
                throw;
            }
        }

The above code works fine if we don't set the SlideSize property. The moment we try to set SlideSize property, the exception is thrown as "PageSetup (unknown member) : Failed." Screenshot of the error message is shown below:

enter image description here

The version of Microsoft.Office.Interop.PowerPoint is 15.0.0.0 and Microsoft Office 15.0 Object Library is used as the Office core library. My PC in Windows 8.1 and I am using Microsoft Office 2013. Since we need custom output format, we need to setup SlideSize property which is currently throwing exception.

1

1 Answers

0
votes

The code you have is correct. I was able to recreate your error exactly with with the presentation being marked as 'Final'. Try adding:

presentation.Final = false;

Add it before you resize. Hope it helps. Good Luck.