Resizing of Slides

Is there a method to change the size of a slide in a presentation (e.g., from 7.5x10 to 15x20) and have it resize the objects on the slide correctly? Basically, do with the API what happens in Powerpoint when you change the Page Setup size? When I use the .getSlideSize().setSize() method it changes the slide page size correctly but the slide elements remain the original size. Thanks, Bob

Hi Bob,

Thanks for your interest in Aspose.Slides.

I have observed the requirement shared by you and suggest you to please try using the following sample code on your end to serve the purpsoe. Please share, if I may help you further in this regard.

public static void SetPresentaitonrResize3()
{
Presentation presentation = new Presentation(“D:\Aspose Data\Good Practices.pptx”);

//Old slide size
double currentHeight = presentation.getSlideSize().getSize().getHeight();
double currentWidth = presentation.getSlideSize().getSize().getWidth();

// presentation.SlideSize.Type = SlideSizeType.A4Paper;
presentation.getSlideSize().setType((byte)SlideSizeType.Custom);

Dimension2D dimension = presentation.getSlideSize().getSize();
dimension.setSize(2072 , 1572);
presentation.getSlideSize().setSize(dimension);



presentation.getSlideSize().setOrientation(SlideOrienation.Portrait);

//New slide size
double newHeight = presentation.getSlideSize().getSize().getHeight();
double newWidth = presentation.getSlideSize().getSize().getWidth();


double ratioHeight = newHeight / currentHeight;
double ratioWidth = newWidth / currentWidth;

for (IMasterSlide master : presentation.getMasters())
{
for (IShape shape : master.getShapes())
{
//Resize position
shape.setHeight ((float)(shape.getHeight() * ratioHeight));
shape.setWidth((float)(shape.getWidth() * ratioWidth));

//Resize shape size if required
shape.setY((float)(shape.getY() * ratioHeight));
shape.setX( (float)(shape.getX() * ratioWidth));

}

for (ILayoutSlide layoutslide : master.getLayoutSlides())
{
for (IShape shape : layoutslide.getShapes())
{
//Resize position
shape.setHeight ((float)(shape.getHeight() * ratioHeight));
shape.setWidth((float)(shape.getWidth() * ratioWidth));

//Resize shape size if required
shape.setY((float)(shape.getY() * ratioHeight));
shape.setX( (float)(shape.getX() * ratioWidth));

}

}
}

for (ISlide slide : presentation.getSlides())
{
for (IShape shape : slide.getShapes())
{
//Resize position
shape.setHeight ((float)(shape.getHeight() * ratioHeight));
shape.setWidth((float)(shape.getWidth() * ratioWidth));

//Resize shape size if required
shape.setY((float)(shape.getY() * ratioHeight));
shape.setX( (float)(shape.getX() * ratioWidth));

if (shape instanceof ITable)
{
ITable table = (ITable)shape;
// for (IRow row : table.getRows())
for (int i=0;i< table.getRows().size();i++)
{
IRow row = table.getRows().get_Item(i);
row.setMinimalHeight ((float)(row.getMinimalHeight() * ratioHeight));
// row.Height = row.Height * ratioHeight;
}
// for (IColumn col : table.getColumns())
for (int i=0;i< table.getColumns().size();i++)
{
IColumn col = table.getColumns().get_Item(i);

col.setWidth ( (float)(col.getWidth() * ratioWidth));

}
}

}
}

presentation.save(“D:\Aspose Data\Good Practices_Land.pptx”, SaveFormat.Pptx);

}


Many Thanks,

Much appreciated - seems to work with everything except text - can you add code to resize the fonts used in each shape or table? Thanks, Bob

Hi Bob,


I have observed your comments and like to share with you that in that case you need to modify text in each cell of the table. I request you to please visit this documentation link for your kind reference.

I hope this will be helpful. Please share if I may help you further in this regard.

Many Thanks,