We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Rectangle Not Automatically Growing

I am working on a proof of concept using Aspose Slides PPT API. I need to add a section on the PPT that will have a header of 24 font size followed by an unknown amount of text of font size 12.

My code is below and a sample is attached.

I am noticing that the rectangle in the generated PPT is too small if the text is over a few lines. Is there a way to tell the rectangle to “auto grow” with the text inside?

// Get template
Presentation resume = new Presentation(new FileInputStream(new File(“C:\data\demo.pot”)));

// Add slide
Slide slide1 = resume.addEmptySlide();

// Add rectangle
Rectangle summaryRectangle = slide.getShapes().addRectangle(90,1100,6000,500);
summaryRectangle.getLineFormat().setShowLines(false);

// Add textframe
TextFrame textFrame = summaryRectangle.addTextFrame("");
textFrame.setWrapText(true);
textFrame.setAnchorText(AnchorText.TOP);

// Add header, set font to 24
Paragraph nameParagraph = new Paragraph();
nameParagraph.setText(“Header”);
textFrame.getParagraphs().add(nameParagraph);
nameParagraph.getPortions().get(0).setFontHeight((short)24);

// Add text below header
Paragraph experienceText = new Paragraph();
experienceText.setText(“This is the text.”); // If this is long, the text overruns the rectangle in the output
textFrame.getParagraphs().add(experienceText);
experienceText.getPortions().get(0).setFontHeight((short)12);

// Remove blank line
textFrame.getParagraphs().removeAt(0);

// Remove blank slide
resume.getSlides().removeAt(0);

// Creating a file output stream to write the output file
FileOutputStream fostream = new FileOutputStream(“C:\data\demo.ppt”);

// Writing the presentation as a PPT file
resume.write(fostream);

Hi Stephen,


Please add the following line to your code snippet after adding the text. Hopefully, it will help you. Please share, if I may help you further.

textFrame.setFitShapeToText(true);

Many Thanks,