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

Free Support Forum - aspose.com

Wrap text

How do you wrap text in a paragraph?

Dear jmitchell421,

If you will set the wrap text property (Textframe.setWrapText) of textframe, then text will be wrapped whenever text will exceeds the boundry of rectangle holding a textframe.

The below JAVA code creates a textframe and sets its wrap text property. It is commented and you can check the effects of various properties by commenting/uncommenting them.

I have also attached the code and the generated presentation.

Presentation pres=new Presentation();

Slide sld=pres.getSlideByPosition(1);

//Wrap text

com.aspose.slides.Rectangle rect=sld.getShapes().addRectangle(100, 100, 800, 300);

//make rectangle lines invisible

rect.getLineFormat().setShowLines(false); //Uncomment this line to make lines invsible

TextFrame tf=rect.addTextFrame(" ");

//Enable the text frame's shape to expand automatically


//Wrap the textframe, if it exceeds rectangle's width


//Set some long text

tf.getParagraphs().get(0).getPortions().get(0).setText("There is a lot of text. There is lot of text.There is a lot of text. There is lot of text.");

//write presentation on disk

pres.write(new FileOutputStream(new File("c:\\outPres.ppt")));

For C# code, see this thread.


what about vb.net code?

can someone help me with the answer in vb???

Below is exactly the same code in VB.NET


Dim pres As New Presentation

Dim sld As Slide = pres.GetSlideByPosition(1)

'Wrap Text

Dim rect As Aspose.Slides.Rectangle

rect = sld.Shapes.AddRectangle(100, 100, 800, 300)

'Make rectangle lines invisible

rect.LineFormat.ShowLines = False

'Add textframe

'Enable the text frame's shape to expand automatically

Dim tf As TextFrame = rect.AddTextFrame(" ")

tf.FitShapeToText = True

'Wrap the textframe, if it exceeds rectangle's width

tf.WrapText = True

'Set some long text.

tf.Paragraphs(0).Portions(0).Text = "There is a lot of text. There is lot of text.There is a lot of text. There is lot of text."

'Write presentation on disk


Dim srcPres As Presentation = New Presentation("c:\formattedText.ppt")

Dim dstPres As Presentation = New Presentation

'Get the reference to first slide by cloning it

Dim srcSld As Slide

srcSld = srcPres.CloneSlide(srcPres.GetSlideByPosition(1), _

dstPres.Slides.LastSlidePosition + 1, dstPres, New SortedList())

'Get the reference to formatted text

'I had set its alternative text to get it quickly

'using findshape method

Dim srcRect As Aspose.Slides.Rectangle

Dim srcTF As TextFrame

srcRect = srcSld.FindShape("formattedText")

srcTF = srcRect.TextFrame

'Add a new text frame on destination presentation

Dim dstSld As Slide

dstSld = dstPres.GetSlideByPosition(1)

'Add the invisible rectangle

Dim dstRect As Aspose.Slides.Rectangle

dstRect = dstSld.Shapes.AddRectangle(400, 600, 3000, 1)

dstRect.LineFormat.ShowLines = False

'Change the background color of the rectangle

'with the source textframe's rectangle

dstRect.FillFormat.Type = srcRect.FillFormat.Type

dstRect.FillFormat.ForeColor = srcRect.FillFormat.ForeColor

'Add textframe inside rectangle

Dim dstTF As TextFrame

dstTF = dstRect.AddTextFrame(" ")

'Textframe's rectangle will expand automatically with more tex

dstTF.FitShapeToText = True

'Text will be wrapped if it exceeds rectangle boundries

dstTF.WrapText = True

'Clear all the portions inside the textframe


'Now clone the portion object

Dim port As Portion, newPort As Portion

port = srcTF.Paragraphs(0).Portions(0)

newPort = New Portion(port)

'Add the some text into newPort

newPort.Text = "I have imported the formatting of the text."

'Add portion into the destination textframe


'Remove the cloned slide


'Finally presentation on disk