Changing slide size pushes text outside of the slide (C# .NET)

Hi,

I am trying to change the slide height of a powerpoint document. But when I do that it pushes everything outside the slide.

var currentHeight = presentationEx.SlideSize.Size.Height;

var currentWidth = presentationEx.SlideSize.Size.Width;

float heightSize = currentHeight - 130;

presentationEx.SlideSize.Type = SlideSizeTypeEx.Custom;

presentationEx.SlideSize.Size = new SizeF(new PointF(currentWidth, heightSize));

Is there a way to fix that?

Thanks.

Hi Maysoon,


Thanks for your interest in Aspose.Slides.

I have observed the issue shared by you. Actually, you are trying to reduce the height of the presentation. In fact when you alter the height of the presentation it does not have on slides placeholders to adjust automatically according to modified slide height. You may need to alter the placeholders heights as well to avoid the text getting overflowed from slide.

Many Thanks,

Can you give an example on how to do that?

Thanks,

Maysoon

Hi Maysoon,


You can implement your own logic for setting the placeholder size in accordance with change slide height. I have created the sample code to serve the purpose in this regard. You may alter it to meet your own needs as well I have shared the source and generated presentations as well for your kind reference.

public static void SetPresentaitonSize()
{
PresentationEx presentationEx = new PresentationEx(“D:\Aspose Data\TestResize.pptx”);
float currentHeight = presentationEx.SlideSize.Size.Height;
float currentWidth = presentationEx.SlideSize.Size.Width;

float heightSize = currentHeight - 130;
presentationEx.SlideSize.Type = SlideSizeTypeEx.Custom;

presentationEx.SlideSize.Size = new SizeF(new PointF(currentWidth, heightSize));

float ratioHeight = heightSize / currentHeight;

foreach (ShapeEx shape in presentationEx.Slides[0].Shapes)
{
shape.Height = (float)(shape.Height * ratioHeight);

}

presentationEx.Write(“D:\Aspose Data\TestResize2.pptx”);

}


Many Thanks,

Hey Mudassir,
What about the tables and other contents other than shape (that got pushed), present in Slide? Is there any neat way like PowerPoint does - Change the size of your slides - Microsoft Support

When PowerPoint is unable to automatically scale your content, it will prompt you with two options:






  • Maximize:Select this option to increase the size of
    your slide content when you are scaling to a larger slide size. Choosing
    this option could result in your content not fitting on the slide.



  • Ensure Fit:Select this option to decrease the size of
    your content when scaling to a smaller slide size. This could make your
    content appear smaller, but you’ll be able to see all content on your
    slide.

How can we do - Maximize and Ensure Fit using Aspose.Slides?

Hi Praneeth,

I have observed your requirement and like to share that for IAutoShapes TextFrame, we have ITecxtFrame.AutofitType property that sets the TextAutoFitType for the TextFrame text. You can use this property to enforce the AutoShape textframe text to remain accommodated inside defined size wihtout exceeding slide size.

As far as AutoFitType for tables is concerned, there is no such implementation available in PowerPoint as well. However, you can follow the workaround approach to see if the table has exceeded slide size or not. The default slide height is 540 ( 7.5’’). It all depends
on number of rows and what row height you set for the table to get the table height .
When the Y position + Table height will exceed the 540 figure, then you
will be needed to add new slide as its going to overflow otherwise.
Suppose the Y position of table is at 30 and you are going to set the
row height 30. If you take these two figure in account then you may add
17 rows with every one having height 30. 17*30 + 30= 540. I hope this
will clarify the concept and you can deal with this accordingly on your
end.

Many Thanks,

For Java:
I tried to do something but got stuck for autofit property:
for(ISlide slide: ppt.getSlides()) {
System.out.println(slide.getSlideNumber());
for(IShape shape: slide.getShapes()) {
System.out.println(shape.getName());
System.out.println(shape.getFrame().getWidth());
System.out.println(shape.getFrame().getHeight());
}
}

Dimension2D dimension = ppt.getSlideSize().getSize();
dimension.setSize(dimension.getWidth() + 5*72, dimension.getHeight());
ppt.getSlideSize().setSize(dimension);

for(ISlide slide: ppt.getSlides()) {
System.out.println(slide.getSlideNumber());
for(IShape shape: slide.getShapes()) {
IAutoShape autoShape = (AutoShape) shape;
// Question #1. How to set the autofit property so that shape will fit automatically?
// Question #2. Is this autofit property fits the image in “Maximize” manner or “Ensure Fit” manner?
autoShape.getTextFrame().getTextFrameFormat().getAutofitType()
System.out.println(shape.getName());
System.out.println(shape.getFrame().getWidth());
System.out.println(shape.getFrame().getHeight());
}
}

Thanks.

PS: I’m now not worried about tables as Aspose.Slides detects it as sort of shape, I think, and we are good on table front. Thanks.

Hi Praneeth,

I like to share that TextAutoFitType.Shape and TextAutoFitType.Normal are two autofit types. The TextAutoFitType.Shape is used to set the shape follow the added text. Whereas, TextAutoFitType.Normal fits the text content inside the shape. Also, the TextAutoFitType is only associated with AutoShape text frames and nothing else. So, your question concerning to image resizing is answered that TextAutoFitType does not work with images or picture frames. The following sample code is a sample code for using the discussed property.

public static void AutoFitTest()
{
//Instantiate PresentationEx//Instantiate PresentationEx
Presentation pres = new Presentation();


//Get the first slide
ISlide sld = pres.getSlides().get_Item(0);

//Add an AutoShape of Rectangle type
IAutoShape ashp = sld.getShapes().addAutoShape(ShapeType.Rectangle, 30, 200, 600, 30);

//Add TextFrame to the Rectangle
ashp.addTextFrame(" “);

//Accessing the text frame
ITextFrame txtFrame = ashp.getTextFrame();

//Setting Autofit type to Shape means that shape will be adjusted based on text
// txtFrame.getTextFrameFormat().setAutofitType(TextAutofitType.Shape);


//Setting Autofit type to Shape means that shape will be adjusted based on text
txtFrame.getTextFrameFormat().setAutofitType(TextAutofitType.Normal);


//Create the Paragraph object for text frame
IParagraph para = txtFrame.getParagraphs().get_Item(0);

//Create Portion object for paragraph
IPortion portion = para.getPortions().get_Item(0);


//Set Text
portion.setText(“Electricite de France SA (EDF) is a France-based electricity producer, marketer and distributor. The company generates energy using nuclear technology, as well as thermal, hydroelectric and other renewable energy sources. EDF also manages low- and medium-voltage public distribution networks and is involved in electricity transmission networks.”
+” Electricite de France SA (EDF) is a France-based electricity producer, marketer and distributor. The company generates energy using nuclear technology, as well as thermal, hydroelectric and other renewable energy sources. EDF also manages low- and medium-voltage public distribution networks and is involved in electricity transmission networks.");


// height of shape remains same(it’s 30) even when text is spilling out of shape(textbox).
float shapeHeightAfterAddingText = ashp.getHeight();

//Save the presentation to disk
pres.save(“D:\Aspose Data\TextBox.pptx”, SaveFormat.Pptx);

}

Many Thanks,

The issues you have found earlier (filed as SLIDESJAVA-34771) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

If I use version 18.9 and I always meet this question,Can I use version 19.3 with my license?

@ximoon,

I like to share that Aspose.Slides 19.3 has been published 03 April. 2019. If your license expiry date is after this release date then you can use the version otherwise, you may need to renew your subscription to use latest version.

But I also met changing the Slide Size pushes text outside of the slide. If I use 18.9,How I can do for solve this problem?

@ximoon,

I request you to please provide source presentation. working sample code, desired and output presentation files. We will be able to investigate the issue further on our end on provision of requested information.

@ximoon,

I have observed the images shared by you. Apparently, code lines in image seems fine. However, in order to investigate the issue further on my end, I need a working sample code along with source presentation. Please share the requested information so that we may proceed further to help you out.

This question is accidental. Not happened with every file.And I was using the version 19.3 of this problem without solving a sentence

Presentation pres = new Presentation();

ISlideCollection slides = pres.getSlides();

IPPImage ippImage = null;

String imagePath = “13339320_183302468194_2.jpg”;
InputStream inputStream = LoadPicUtil.loadPic(imagePath);

if (inputStream != null) {
try {
ippImage = pres.getImages().addImage(inputStream);
} catch (Exception e) {
System.out.println(“图片下载异常”);
}
}

IShapeCollection shapes = slides.get_Item(0).getShapes().addGroupShape().getShapes();

IPictureFrame iPictureFrame = shapes.addPictureFrame(ShapeType.Rectangle, 0,
0, 100, 100, ippImage);

IAutoShape calloutWedgeRectangle = shapes.addAutoShape(ShapeType.CalloutWedgeRectangle, 10, 10, 0, 0);

calloutWedgeRectangle.getTextFrame().getTextFrameFormat().setAnchoringType(TextAnchorType.Bottom);
calloutWedgeRectangle.getTextFrame().getTextFrameFormat().setAutofitType(TextAutofitType.Shape);
calloutWedgeRectangle.getTextFrame().getTextFrameFormat().setWrapText(NullableBool.False);
calloutWedgeRectangle.getTextFrame().setText(“I am a calloutWedgeRectangle”);
calloutWedgeRectangle.getTextFrame().getParagraphs().get_Item(0).getParagraphFormat().setAlignment(TextAlignment.Left);

pres.save(FILE_PATH + “AddTextForImage.pptx”, SaveFormat.Pptx);
2019-05-31_144114.jpg (100.7 KB)

this is my code. Thanks.

If I run on local,it is ok.But content will out of border range when my code run on server.what `s the question?

@ximoon,

I have worked with source code shared by you. For further investigation, can you please share image file which you are loading in your sample code so that we may help you out.

I don`t know what caused it
2019-06-03_090828.jpg (50.4 KB)

@ximoon,

Please provide the following image file referred in your sample code so that we may verify this on our end.