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

Extra newline in copied RTF content

3 Answers 204 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Yiannis
Top achievements
Rank 1
Yiannis asked on 14 Feb 2020, 04:40 PM

Due to the RtfFormatProvider not respecting the existence or lack of a newline Inline at the end of the last Paragraph of the RadDocument, copying sth that does not end with a newline adds an extra final newline marker ("\par") at the end of the copied RTF.

While RadRichTextBox handles this gracefully when pasting (by ignoring the extra "\par"), other applications, e.g. Wordpad, include that newline with the pasted contents.

For example, copying a single letter "L" from the middle of a sentence in a RadRichTextBox and pasting it in Wordpad, one will get "L" followed by an extra Paragraph.

 

Short of creating another RTF provider and filtering out that last "\par", can you suggest another way to avoid adding extra newlines when exporting non-closed paragraphs to RTF? I may have missed something, but there is no option to control that in the RtfFormatProvider code.

 

Thanks in advance!

3 Answers, 1 is accepted

Sort by
0
Accepted
Tanya
Telerik team
answered on 17 Feb 2020, 08:19 AM

Hello Yiannis,

I am sorry to hear about the issue you are experiencing with this behavior.

We have this issue already logged in our backlog and you can subscribe to receive updates about status changes on it through the Follow button on the public item: RichTextBox: An additional paragraph is added at the end when exporting content to RTF. This item also contains the best possible workaround we have found - it is the same as what you mentioned, though. Since the logic of the format provider is internal, I am afraid that there isn't an option for changing its behavior prior to the export.

Hope this information is useful.

Regards,
Tanya
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Yiannis
Top achievements
Rank 1
answered on 18 Feb 2020, 01:55 AM

Thank you Tanya for the update.

 

I mentioned creating another provider because I accidentally discovered that if there is any custom provider with "rtf" in its SupportedExtensions (in my case, I had derived the provider from RtfFormatProvider), it ends up being used for exporting Copy/Cut content because 'DocumentFormatProvidersManager.GetProviderByExtension("rtf")' returns the custom provider. I am not sure I can rely on that, though, because it looks non-deterministic.

I was actually thinking of filtering out the extra '\par' at the Stream level using a custom provider and a filtering Stream, so that the RTF string is not copied around too much.

0
Accepted
Tanya
Telerik team
answered on 18 Feb 2020, 09:42 AM

Hi Yiannis,

The API of RadRichTextBox provides you with the ability to create a custom format provider but you should have in mind that this wouldn't be a trivial task. On the other hand, you could use the already existing logic of RtfFormatProvider and modify the stream object produced by the Export() method. In this case, you will need to ensure that the structure of the RTF document is not broken during the modification. You can find an example of creating a custom format provider in our SDK repository: https://github.com/telerik/xaml-sdk/tree/master/RichTextBox/DocFormatProviderDemo.

Regards,
Tanya
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
RichTextBox
Asked by
Yiannis
Top achievements
Rank 1
Answers by
Tanya
Telerik team
Yiannis
Top achievements
Rank 1
Share this question
or