Free Support Forum - aspose.com

Page Breaks in Slide portions

I seached but couldn't find the answer to this, so I apologize if this is a duplicate.

When assigning text to a slide portion I see we cannot use vbCrLf, vbCr, vbLf (causes an error) or \r, \n (shows up as literal text). So, how do I add a carriage return to the text in a Slide portion?

Thanks

Please see this thread.

<A href="</A></P>

The simple things have become so difficult recently. I 'm using a template with various formats in the header, center, and footer. I want to add four words to the header (with a CR) WITHOUT losing the formatting of the existing textframe.

FORMATTED HEADER:

HeaderText

GOAL:

Range Instrumentation

Maintenance Status

METHOD #1

Dim P1 As New Aspose.Slides.Paragraph

Dim P2 As New Aspose.Slides.Paragraph

Dim POR1 As New Aspose.Slides.Portion

Dim POR2 As New Aspose.Slides.Portion

Dim POR3 As New Aspose.Slides.Portion

tf = title.GetCell(0, 0).TextFrame

tf.paragraphs.Clear()

P1.Portions.Clear()

POR1.Text = "Range Instrumentation"

POR2.Text = "Maintenance Summary"

P1.Portions.Add(POR1)

P1.Portions.Add(POR2)

tf.Paragraphs.Add(P1)

RESULT

§Range InstrumentationMaintenance Summary

IF I ELIMINATE THE CLEARS()

HeaderText

§Range InstrumentationMaintenance Summary
METHOD #2

tf = title.GetCell(0, 0).TextFrame

P1.Text = "Range Instrumentation"

P2.Text = "Maintenance Summary"

tf.Paragraphs.Add(P1)

tf.Paragraphs.Add(P2)

RESULT (AT LEAST I GOT THE CR)

HeaderText

§Range Instrumentation
§Maintenance Summary

Dear dfiala,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Formatting of the text is preserved by Portion object, I mean; it is preserved only, when you set the text with Portion.Text property and lost, if you set it via TextFrame.Text or Paragraph.Text properties.

I think, this is what you want, please see the code below and output presentation attached by me. Source presentation is also attached.

------------------------------------------------------------------------

VB.NET CODE

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

Dim sld As Slide = pres.GetSlideByPosition(1)

Dim shp As Shape = sld.Shapes(0)

Dim tf As TextFrame = shp.TextFrame

Dim paras As Paragraphs = tf.Paragraphs

Dim para As Paragraph = paras(0)

'Now add two lines with the same formatting

Dim newPara As Paragraph = New Paragraph(para)

newPara.Portions(0).Text = "Range Instrumentation"

paras.Add(newPara)

'One more

newPara = New Paragraph(para)

newPara.Portions(0).Text = "Maintenance Status"

paras.Add(newPara)

pres.Write("c:\outPres.ppt")

Seems to work - thanks.

One last question. Is there anyway to clear the placeholder text without losing the formatting? The Clear() property seems to clear everything.

No, to keep your formatting intact, you will have to get and save the copy of one portion object before clearing and place it back. e.g

Note: Clear method just erase all the objects from collections like from TextFrame.Paragraphs or TextFrame.Paragraphs[0].Portions

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Portion oldPort=thld.Paragraphs[0].Portions[0];

Portion <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />newPort=new Portion(oldPort);

//Clear the existing text cloned from oldPort

//leave one space or one character

newPort.Text=” “;

//Clear all paragraphs

//it will clear all text

thld.Paragraphs.Clear();

//Add new paragraph and new portion

Paragraph newPara=new Paragraph();

newPara.Portions.Add(newPort);

thld.Paragraphs.Add(newParagraph);