Text line break example

Hi ,

Does anyone can show me a simple example with line break in aspose.slide

I have a web project using asp.net (VB code base) with a remark text field. the text field will allow user to input a text in point form. I need to slow that remark string into the powerpoint slide. however, it is not allow line break in aspose.slide. Does anyone can show me a simple example ??

please help!

thanks

hlche3

Did you read my answer in previous thread? Ok, let’s repeat it.

1. Put text with line breaks to TextFrame.Text property.
shape.TextFrame.Text = “Text with \n line breaks”;

2. Split your input text by yourself and create paragraphs.


string sometext = “Text with \n line breaks”;

Paragraphs paras = shape.TextFrame.Paragraphs;



char[] delimiters = new char[] {’\r’, ‘\n’};

string[] split = sometext.Split(delimiters);

paras[0].Portions[0].Text = split[0];

for (int i = 1; i < split.Length; i++) {

paras.Insert(i, new Paragraph(paras[i - 1]));

paras[ i ].Portions.Clear();

paras[ i ].Portions.Add(new Portion(paras[0].Portions[0]));

paras[ i ].Portions[0].Text = split[ i ];

}

Could you tell me what you can’t understand in these 2 examples?

The same in VB.Net

1.
shape.TextFrame.Text = “Text with \n line breaks”

2.
Dim sometext As String = “Text with \n line breaks”
Dim paras As Paragraphs = shape.TextFrame.Paragraphs

Dim delimiters() As Char = New Char() {"\r"c, "\n"c}

Dim split() As String = sometext.Split(delimiters)
paras(0).Portions(0).Text = split(0)
Dim i As Integer
For i = 1 To split.Length - 1
paras.Insert(i, New Paragraph(paras(i - 1)))
paras( i ).Portions.Clear()
paras( i ).Portions.Add(New Portion(paras(0).Portions(0)))
paras( i ).Portions(0).Text = split( i )
Next

ai.....! thanks alot

dont know why~ the first vb.net method doesnt work. but work fine with the second one~

I will use the second one for my coding~ thanks!!

That is true even for the java methods, the first one with linebreaks doesnt work but the second one works

The first should work too. Try something like this:

shape.getTextFrame().setText(“Text with linebreaks \n one more line”);

Hi,

I have tried the following piece of code to show the text in different paragraphs.

But this is giving lots of error.

TextFrame tf = shapes.getTextFrame();

String descriptionText = "abcd \n efgh \n ijklm";

Paragraphs paras = tf.getParagraphs();
String delimiters = "\n";
String[] split = descriptionText.split(delimiters);
paras.get(0).getPortions().get(0).setText(descriptionText) = split[0];
for (int i = 0; i < split.length; i++) {
paras.add(i, new Paragraphs(paras[i - 1]));
paras.get(i).getPortions().clear();
paras.get(i).getPortions().add(new Portions(paras.get(0).getPortions().get(0)));
paras.get(i).getPortions().get(0).setText() = splitIdea [I];
}

Please let me know where I am making wrong.

Dear mridul_paul,

Thank you for using Aspose.Slides

One problem, which I can see is that for loop should start from i=1 rather than i=0

Hi,

Still this is giving errors.

The error is as follows:

java.lang.Error: Unresolved compilation problems:

The left-hand side of an assignment must be a variable

The method add(Paragraph) in the type Paragraphs is not applicable for the arguments (int, Paragraphs)

The type of the expression must be an array type but it resolved to Paragraphs

The method add(Portion) in the type Portions is not applicable for the arguments (Portions)

The constructor Portions(Portion) is undefined

The left-hand side of an assignment must be a variable

Dear mridul_paul,

Below is the changed code, try it, does it work for you? and if you still get errors what are those?


TextFrame tf=shapes.getTextFrame();
String descriptionText="abcd \n efgh \n ijklm";
Paragraphs paras=tf.getParagraphs();

String delimiters="\n";
String[] split=descriptionText.split(delimiters);

paras.get(0).getPortions().get(0).setText(split[0]);

for (int i = 1; i < split.length; i++)
{
paras.add(i, new Paragraphs(paras[i - 1]));
paras.get(i).getPortions().clear();
paras.get(i).getPortions().add(new Portion(paras.get(0).getPortions().get(0)));
paras.get(i).getPortions().get(0).setText(splitIdea [I]);
}

Hi,

I changed the code according to your code but it is still giving an error at

paras.add(i, new Paragraphs(paras[i - 1]));

The error is:

java.lang.Error: Unresolved compilation problems:

The method add(Paragraph) in the type Paragraphs is not applicable for the arguments (int, Paragraphs)

The type of the expression must be an array type but it resolved to Paragraphs

at com.novartis.pptutilwithAspose.ComplianceInitiativeOverviewPage.createAndShowComplianceInitiativeOverviewPage(ComplianceInitiativeOverviewPage.java:61)

at com.novartis.pptutilwithAspose.Sample.main(Sample.java:80)

Exception in thread "main"

Thanks


Dear mridul_paul,

Change it into paras.add( new Paragraph(paras[i - 1]));

And then see, does it compile and execute as expected?

Probably next line should be more correct:

paras.add(new Paragraph(paras.get(i - 1));

Hi,

Many many thanks for the help. It is working now.