2

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

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;

        Code more ...

This result is not what I expected ; Now, how to set the Presentations or slide(PPT) pagsize?

klashar
  • 2,519
  • 2
  • 28
  • 38
doo0301
  • 51
  • 1
  • 3

2 Answers2

1

Not sure if this is exactly what you're looking for, but it's how I've been setting the slide size.

this.Application.ActivePresentation.PageSetup.SlideHeight = <your slide height>;
this.Application.ActivePresentation.PageSetup.SlideWidth = <your slide width>;

Allows you to set the width and height of the slide in points, not pixels. You can use the below to convert pixels to points

private int PixelsToPoints(int pixels)
{
     return pixels * 72 / 96;
}
Sandwich
  • 356
  • 7
  • 18
  • Try running your code. the error msg is " Invalid request. There is no active presentation." why?? – doo0301 Feb 22 '17 at 14:04
  • Have you tried the code after creating a presentation? I'm running it when a presentation has been created, and a slide is visible. It then adjusts the size of the slide, and subsequent slides – Sandwich Feb 22 '17 at 14:58
  • @Sandwich Thanks for your help, I found the problem, it is this line of code can not achieve the desired effect, I changed the other way – doo0301 Feb 22 '17 at 15:03
  • @Sandwich Could you please mention where the "72" value comes from? What's the point of it? – Nahuel Ianni Jun 12 '17 at 11:49
0

now,this is right code:

        PowerPoint.Application pptApp = new PowerPoint.Application();
        MyPres = pptApp.Presentations.Add(MsoTriState.msoTrue);
        MyPres.PageSetup.SlideWidth = <slide width>;
        MyPres.PageSetup.SlideHeight = <slide height >;

This line of code have bug?, I'm not sure !!

        MyPres.PageSetup.SlideSize = PowerPoint.PpSlideSizeType.ppSlideSizeOnScreen16x9;
doo0301
  • 51
  • 1
  • 3