0

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.

Saket Kumar
  • 4,363
  • 4
  • 32
  • 55

1 Answers1

0

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.

  • Hey there! I tried adding presentation.Final = false; before setting the SlideSize property, but didn't have any luck. I am still getting the same issue. Any guess what might be causing the same issue? – Saket Kumar Feb 06 '17 at 09:59
  • It more than likely is happening because the file is locked, marked as Final, or is in Read-Only status. I would try and see if you can edit another file as well and see if you get the same result. I can tell you that your code written should work as long as you have the ability to edit the file. – Musical Beard Feb 06 '17 at 13:13
  • The file I am trying to convert is not locked or read only. Still, for some reason, I am getting this exception. I wish I could figure out what the issue is. – Saket Kumar Feb 10 '17 at 06:47
  • Try creating a new file locally and try editing that power point. If the error does not happen you will have isolated the issue to the file. If the error still happens with the new file then we know that it is related to code or setup. Let me know if the result and I will try and steer you in the right direction. – Musical Beard Feb 10 '17 at 13:54
  • I copied and pasted your code to test it out again and was able to run it without errors with the exact same setup. Leads me to believe it is the file. – Musical Beard Feb 10 '17 at 14:04