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.
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”);
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?
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.
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()); } }
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.
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);
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.
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.
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.
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);
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.