How shorten the output string of RtfFormatProvider.Export(radDocument)?

2 posts, 0 answers
  1. Lukas
    Lukas avatar
    20 posts
    Member since:
    Jul 2011

    Posted 31 Jul 2012 Link to this post

    Dear Telerik team,

    I'm facing following problem: in our application there is all over the place the chance to put rich text into a master item. This master item holds RTF strings in data fields. Those master items can theoratically hold an infinite amount of data fields. Technically there is a chance to save on each of these data fields one RTF string. We're using strings instead of documents, because they need less disk space and are faster to handle.

    We achieve that with using the RadRichTextBox and the RtfFormatProvider. We double check if there is actual text in the RichTextBox before saving it (converting it with TxtFormatProvider). There is are lots of big texts stored in our DB, but imagine 30% out of ten thousands of records just hold a couple of words. The string, which is generated for standard styles (probably defined in the RtfFormatProvider class) is way bigger than the actual text. And if we save those everytime, maybe half of the disk space used by our application DB is because of those default styles.

    Simple demonstration:

    private void GenerateEmptyRtf()
        var doc = new RadDocument();
        var str = new RtfFormatProvider().Export(doc);

    Even though the document doesn't hold any content, at all, the string is huge.

    I thought already about manually appending and trimming off those styles, everytime I get a RTF string from the DB. But I cannot really provide, that this happens properly (RegExp or similar stuff).

    There is absolutely no other way than saving it in the RichTextFormat.

    I really hope there is a proper solution. Any help is greatly appreaciated.
  2. Vasil
    Vasil avatar
    124 posts

    Posted 03 Aug 2012 Link to this post

    Hello Lukas,

    The greatest impact to the size of the exported RTF string is due to the styles that are added to each new document - Heading 1, Heading 2, etc. You could remove unnecessary style definitions from the StyleRepository of the document just after it is created in case they won't be used. Please refer to this forum post answer for more information.

    I hope this information helps. Don't hesitate to contact us if you have other questions.

    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top