This is a migrated thread and some comments may be shown as answers.

RadDocument Insert LineBreak in span

8 Answers 652 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 02 Dec 2012, 11:16 PM
I am inserting some text that conains linebreaks, "\n", into a new Span in a RadDocument based on a docx template and then I save the document as a PDF using the PDF provider.

The problem is that there is everything is printed on the same line and the LineBreake itself i replaced by two Squares (i asume that is since the LineBreak character is not recognized).

I have tried replacing the LineBreak with "FormattingSymbolLayoutBox.LINE_BREAK", but the text is still on one line and I get a ¬ character instead of the two Squares.

Is it impossible to insert a LineBreak inside a Span, or is it possible to fix this?

Please note that I am only using the RadDocument class and that I am not and do not want to use the actual RichTextBox Control!

8 Answers, 1 is accepted

Sort by
0
Petya
Telerik team
answered on 04 Dec 2012, 11:40 AM
Hello Thomas,
Generally, a span that contains "\n" in it is considered invalid, so you shouldn't be using this method when creating your document. The proper way to add a line break would be the second approach you mentioned - inserting FormattingSymbolLayoutBox.LINE_BREAK. The ¬ character, on the other hand, is the symbol used for adding line breaks in the document.
So, a correctly structured document would look something like this:
RadDocument document=new RadDocument();
Section section = new Section();
Paragraph paragraph1 = new Paragraph();
Span span1 = new Span("Some text in the first span. ");
 
paragraph1.Inlines.Add(span1);
paragraph1.Inlines.Add(new Span(FormattingSymbolLayoutBox.LINE_BREAK));
Span span2 = new Span("Some more text after the line break in the same paragraph.");
paragraph1.Inlines.Add(span2);
 
Paragraph paragraph2 = new Paragraph();
Span span3=new Span("Last paragraph");
paragraph2.Inlines.Add(span3);
 
section.Blocks.Add(paragraph1);
section.Blocks.Add(paragraph2);
 
document.Sections.Add(section);
and will indeed contain the ¬ character when exported to XAML, for example.

I also tried exporting to PDF the document above and it all looks good on my end. Can you please verify that and contact us again if you are observing different behavior?

Let me know how it goes.

 
Greetings,
Petya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Doug
Top achievements
Rank 1
answered on 21 Apr 2015, 02:04 PM

Using FormattingSymbolLayoutBox.LINE_BREAK within a Span worked for us until we recently upgraded to version 2015.1.401.45. Now our document literally displays the ¬ symbol. Please help!

pragraph.Inlines.Add(new Span(FormattingSymbolLayoutBox.LINE_BREAK + "Some more text after the line break in the same paragraph");
    

0
Tanya
Telerik team
answered on 22 Apr 2015, 01:39 PM
Hi Doug,

In Q1 2015 we introduced a new Break element into the model of RadDocument. With the current version of RadRichTextBox, if you insert a line break symbol ("¬") or a page break symbol ("◊"), a break will not be inserted in the document. You can use the Break class, which is described in our documentation.

All the changes introduced in our controls are listed in the Changes and Backward Compatibility section for the control.

Hope this helps.

Regards,
Tanya
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Ad
Top achievements
Rank 2
answered on 22 May 2015, 08:28 AM
Using the 'Break' class indeed solves the problem, thanks.
0
kalpa
Top achievements
Rank 1
answered on 22 Dec 2017, 10:43 AM

Hi Petya's'

i am trying to add a section break in a specific location. First i add a "[Section Break]" and after that i try to replace it with a section break.i added my code here. please give me a way to do that. i added page break this way but i cant do that for section break.

 

0
Peshito
Telerik team
answered on 26 Dec 2017, 02:58 PM
Hello,

Could you elaborate a bit more on the scenario you are working on? The screenshot of your code is not enough to fully replicate the case. Please have in mind that Sections are positioned above Paragraphs in document's Element Hierarchy. This is why the same approach working for inserting Page Breaks might not work for inserting Section Breaks.A sample project illustrating both approaches you are working on will help in isolating the issue. 

In the meantime the code below shows a possible approach to insert a Section Break using RadRichTextBox' Search functionality.
this.radRichTextBox.Document.Selection.Clear(); // this clears the selection before processing
DocumentTextSearch search = new DocumentTextSearch(this.radRichTextBox.Document);
foreach (var textRange in search.FindAll("\\[Section Break\\]"))
{
    this.radRichTextBox.Document.Selection.AddSelectionStart(textRange.StartPosition);
    this.radRichTextBox.Document.Selection.AddSelectionEnd(textRange.EndPosition);
}
this.radRichTextBox.InsertSectionBreak(SectionBreakType.Continuous);
It finds the string passed as an argument to FindAll() method and inserts Section Break over its place.

Hope this helps.

Regards,
Peshito
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
kalpa
Top achievements
Rank 1
answered on 27 Dec 2017, 10:02 AM

Hi Peshito,

Thanks for your reply. currently we are using radeditor(asp.net ajax) and we use radflowdocument to generate to word. please tell me a way to do this using radflowdocument. 

0
Boby
Telerik team
answered on 28 Dec 2017, 07:23 AM
Hello Kalpa,

Could you please open a separate support thread in WordsProcessing forum? I can see that you already initiated a discussion here, if this is sufficient, we can continue the conversation there.

Regards,
Boby
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
RichTextBox
Asked by
Thomas
Top achievements
Rank 1
Answers by
Petya
Telerik team
Doug
Top achievements
Rank 1
Tanya
Telerik team
Ad
Top achievements
Rank 2
kalpa
Top achievements
Rank 1
Peshito
Telerik team
Boby
Telerik team
Share this question
or