How to set the Presentations or slide(PPT) pagsize in PowerPoint using C# interop library? RRS feed

  • Question


     I  want to set the Presentations pagsize is "ppSlideSizeOnScreen16x9"

    // Create new Slide
    PowerPoint.Application pptApp = new PowerPoint.Application(); MyPres = pptApp.Presentations.Add(MsoTriState.msoFalse); MyPres.Final = false; MyPres.PageSetup.SlideSize = PowerPoint.PpSlideSizeType.ppSlideSizeOnScreen16x9;

    This result is not what I expected ;

    • Edited by doo0301 Wednesday, February 22, 2017 3:09 PM
    Wednesday, February 22, 2017 3:08 PM

All replies

  • Hi doo0301,

    I try to test that property on my side.

    I used code below and set slide size to 16*9.

    private void button1_Click(object sender, EventArgs e)
                string pictureFileName = @"C:\Users\v-padee\Desktop\pexels-photo-27714.jpg";
                Microsoft.Office.Interop.PowerPoint.Application pptApplication = new Microsoft.Office.Interop.PowerPoint.Application();
                Microsoft.Office.Interop.PowerPoint.Slides slides;
                Microsoft.Office.Interop.PowerPoint._Slide slide;
                Microsoft.Office.Interop.PowerPoint.TextRange objText;
                // Create the Presentation File
                Presentation pptPresentation = pptApplication.Presentations.Add(MsoTriState.msoTrue);
                pptPresentation.PageSetup.SlideSize= Microsoft.Office.Interop.PowerPoint.PpSlideSizeType.ppSlideSizeOnScreen16x9;
                Microsoft.Office.Interop.PowerPoint.CustomLayout customLayout = pptPresentation.SlideMaster.CustomLayouts[Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutText];
                // Create new Slide
                slides = pptPresentation.Slides;
                slide = slides.AddSlide(1, customLayout);
                // Add title
                objText = slide.Shapes[1].TextFrame.TextRange;
                objText.Text = "demo";
                objText.Font.Name = "Arial";
                objText.Font.Size = 32;
                objText = slide.Shapes[2].TextFrame.TextRange;
                objText.Text = "Content goes here\nYou can add text\nItem 3";
                Microsoft.Office.Interop.PowerPoint.Shape shape = slide.Shapes[2];
                slide.Shapes.AddPicture(pictureFileName, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, shape.Left, shape.Top, shape.Width, shape.Height);
                slide.NotesPage.Shapes[2].TextFrame.TextRange.Text = "This demo ppt is created by powerpoint using C#";
              //  pptPresentation.SaveAs(@"C:\Users\v-padee\Desktop\fppt.pptx", Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault, MsoTriState.msoTrue);

    it set the slide size as 16*9. you had mentioned that the result is not what you expect.

    can you tell me what is your expected result?

    I did not find anything unexpected.


    PageSetup.SlideSize Property

    PpSlideSizeType Enumeration



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Thursday, February 23, 2017 12:46 AM
  • Here is an alternative solution based on free Spire.Presenation.

    Presentation presentation = new Presentation();
    presentation.SlideSize.Type = SlideSizeType.Screen16x9;

    Friday, February 24, 2017 7:02 AM