Data generated by RtfFormatProvider.Export

4 posts, 1 answers
  1. Marc
    Marc avatar
    2 posts
    Member since:
    Jul 2012

    Posted 09 Jul 2012 Link to this post

    Hi,

    We recently updated our version of Telerik and I noticed a change in the content generated by the Export operation of the RtfFormatProvider. To better illustrate this, here's the result of an empty document exported to RTF for both the former and the new version of Telerik, using the following line of code :

    new RtfFormatProvider().Export(new RadDocument());

    With our former version (2011.3.1116.35), the result was the following (374 characters) :

    {\rtf\ansi\ansicpg1252\uc1\deff0\deflang1033{\fonttbl{\f0 Verdana;}}{\colortbl\red0\green0\blue0 ;\red255\green255\blue255 ;}\nouicompat\viewkind4\paperw12240\paperh15840\margl1425\margr1425\margt1425\margb1425\deftab720\sectd\pgwsxn12240\pghsxn15840\marglsxn1425\margrsxn1425\margtsxn1425\margbsxn1425\headery720\footery720\pard\ltrpar\fs24\sl276\slmult1\sa180{\ltrch}\par}

    With the new version (2012.2.0607.35), the result looks like this (3857 characters) :

    {\rtf\ansi\ansicpg1252\uc1\deff0\deflang1033{\fonttbl{\f0 Verdana;}{\f1 Calibri;}}{\colortbl\red0\green0\blue0 ;\red255\green255\blue255 ;\red79\green129\blue189 ;\red0\green0\blue255 ;}{\*\defchp\ltrch\fs24\i0\b0\strike0\ulnone}{\*\defpap\sl276\slmult1\sa180}{\stylesheet{\*\ts2\tsrowd\sqformat\trbrdrt\brdrnone\trbrdrb\brdrnone\trbrdrl\brdrnone\trbrdrr\brdrnone\trbrdrh\brdrnone\trbrdrv\brdrnone\trgaph0\clpadft3\clpadt75\clpadfr3\clpadr75\clpadfl3\clpadl0\clpadfb3\clpadb0\tsvertalt\ltrch\i0\b0\strike0\ulnone\sl276\slmult1\sa180 TableNormal;}{\*\ts3\tsrowd\sbasedon2\sqformat\trbrdrt\brdrs\brdrw15\brdrcf0\trbrdrb\brdrs\brdrw15\brdrcf0\trbrdrl\brdrs\brdrw15\brdrcf0\trbrdrr\brdrs\brdrw15\brdrcf0\trbrdrh\brdrs\brdrw15\brdrcf0\trbrdrv\brdrs\brdrw15\brdrcf0\trgaph0\clpadft3\clpadt75\clpadfr3\clpadr75\clpadfl3\clpadl0\clpadfb3\clpadb0\tsvertalt\ltrch\i0\b0\strike0\ulnone\sl240\slmult1 TableGrid;}{\s0\sqformat\ltrch\i0\b0\strike0\ulnone\sl276\slmult1\sa180 Normal;}{\s5\sbasedon0\slink4\snext0\sqformat\ltrch\fs28\i0\b\strike0\cf2\ulnone\sl276\slmult1\sb480 Heading 1;}{\*\cs4\additive\slink5\ltrch\fs28\i0\b\strike0\cf2\ulnone Heading 1 Char;}{\s7\sbasedon0\slink6\snext0\sqformat\ltrch\fs26\i0\b\strike0\cf2\ulnone\sl276\slmult1\sb200 Heading 2;}{\*\cs6\additive\slink7\ltrch\fs26\i0\b\strike0\cf2\ulnone Heading 2 Char;}{\s9\sbasedon0\slink8\snext0\sqformat\ltrch\i0\b\strike0\cf2\ulnone\sl276\slmult1\sb200 Heading 3;}{\*\cs8\additive\slink9\ltrch\i0\b\strike0\cf2\ulnone Heading 3 Char;}{\s11\sbasedon0\slink10\snext0\sqformat\ltrch\i\b\strike0\cf2\ulnone\sl276\slmult1\sb200 Heading 4;}{\*\cs10\additive\slink11\ltrch\i\b\strike0\cf2\ulnone Heading 4 Char;}{\s13\sbasedon0\slink12\snext0\sqformat\ltrch\i0\b0\strike0\cf2\ulnone\sl276\slmult1\sb200 Heading 5;}{\*\cs12\additive\slink13\ltrch\i0\b0\strike0\cf2\ulnone Heading 5 Char;}{\s15\sbasedon0\slink14\snext0\sqformat\ltrch\i\b0\strike0\cf2\ulnone\sl276\slmult1\sb200 Heading 6;}{\*\cs14\additive\slink15\ltrch\i\b0\strike0\cf2\ulnone Heading 6 Char;}{\s17\sbasedon0\slink16\snext0\sqformat\ltrch\i\b0\strike0\ulnone\sl276\slmult1\sb200 Heading 7;}{\*\cs16\additive\slink17\ltrch\i\b0\strike0\ulnone Heading 7 Char;}{\s19\sbasedon0\slink18\snext0\sqformat\ltrch\fs20\i0\b0\strike0\ulnone\sl276\slmult1\sb200 Heading 8;}{\*\cs18\additive\slink19\ltrch\fs20\i0\b0\strike0\ulnone Heading 8 Char;}{\s21\sbasedon0\slink20\snext0\sqformat\ltrch\fs20\i\b0\strike0\ulnone\sl276\slmult1\sb200 Heading 9;}{\*\cs20\additive\slink21\ltrch\fs20\i\b0\strike0\ulnone Heading 9 Char;}{\s22\sbasedon0\snext0\sqformat\ltrch\f1\fs18\i0\b\strike0\cf2\ulnone\sl240\slmult1\sa180 caption;}{\s23\sbasedon0\snext0\ltrch\i0\b0\strike0\ulnone\sl276\slmult1\sa100 toc 1;}{\s24\sbasedon0\snext0\ltrch\i0\b0\strike0\ulnone\sl276\slmult1\li220\lin220\sa100 toc 2;}{\s25\sbasedon0\snext0\ltrch\i0\b0\strike0\ulnone\sl276\slmult1\li440\lin440\sa100 toc 3;}{\s26\sbasedon0\snext0\ltrch\i0\b0\strike0\ulnone\sl276\slmult1\li660\lin660\sa100 toc 4;}{\s27\sbasedon0\snext0\ltrch\i0\b0\strike0\ulnone\sl276\slmult1\li880\lin880\sa100 toc 5;}{\s28\sbasedon0\snext0\ltrch\i0\b0\strike0\ulnone\sl276\slmult1\li1100\lin1100\sa100 toc 6;}{\s29\sbasedon0\snext0\ltrch\i0\b0\strike0\ulnone\sl276\slmult1\li1320\lin1320\sa100 toc 7;}{\s30\sbasedon0\snext0\ltrch\i0\b0\strike0\ulnone\sl276\slmult1\li1540\lin1540\sa100 toc 8;}{\s31\sbasedon0\snext0\ltrch\i0\b0\strike0\ulnone\sl276\slmult1\li1760\lin1760\sa100 toc 9;}{\s32\sbasedon0\snext0\ltrch\i0\b0\strike0\ulnone\sl276\slmult1 table of figures;}{\*\cs33\additive\sqformat\ltrch\i0\b0\strike0\cf3\ulc3\ul Hyperlink;}}\nouicompat\viewkind4\paperw12240\paperh15840\margl1425\margr1425\margt1425\margb1425\deftab720\sectd\pgwsxn12240\pghsxn15840\marglsxn1425\margrsxn1425\margtsxn1425\margbsxn1425\headery720\footery720\pard\s0\ltrpar\sl276\slmult1\sa180{\ltrch\i0\b0\strike0\ulnone\par}}

    The problem is that my client wants this data saved in a legacy database where the lengh of the data is restricted. With the tags generated by the new version, in the best case scenario, it severely restricts the amount of actual text that can be entered by the users, while in the worst case scenario the tags themselves are enough to exceed the restrictions.

    Is there any way I could limit the amount of tags that are generated by default? Anything nearing what was generated by our former version 2011.3.1116.35 would be ideal.

    If it can't be done, any other suggestion would also be welcome, knowing that :
    • I have no choice but to use RtfFormatProvider
    • The restrictions on the legacy database can't be changed in any way
    • Data can be restricted to as few as 2000 characters

    Thank you!
  2. Answer
    Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 11 Jul 2012 Link to this post

    Hello Marc,

    The output of RtfFormatProvider in the newer versions is longer because it includes the recently introduced functionality. Basically, when new features are added, they must be properly serialized and deserialized.

    Biggest impact on the size of the generated string have the introduction of headers and footers, as well as styles. (In one of the latest versions we have introduced styles like Heading 1, Heading 2, etc. There are a number of default styles which are added to the document by default, so that they can be used right away.)
     
    While there is no way to disable the export of the header and footer related content, you can remove the export of the styles.

    If you don't allow the use of styles in your application, you can remove these styles from the StyleRepository of the document and they will not be exported. This must be done both on Editor_Loaded and on CommandExecuted, if the command is NewDocumentCommand, as each document has its own StyleRepository:

    RadRichTextBox richTextBox = (RadRichTextBox)sender;
    foreach (var style in richTextBox.Document.StyleRepository.ToList())
    {
        string styleName = style.Name;
        if (styleName.StartsWith("Heading") || styleName.StartsWith("TOC") || styleName.Equals("Caption") || styleName.Equals("TableofFigures"))
        {
            richTextBox.Document.StyleRepository.Remove(style);
        }
    }

    In this way, only the default paragraph style, the hyperlink style and a few more that RadDocument depends on will be serialized:
    {\rtf\ansi\ansicpg1252\uc1\deff0\deflang1033{\fonttbl{\f0 Verdana;}}{\colortbl\red0\green0\blue0 ;\red255\green255\blue255 ;\red0\green0\blue255 ;}{\*\defchp\ltrch\fs24\i0\b0\strike0\ulnone}{\*\defpap\sl276\slmult1\sa180}{\stylesheet{\*\ts2\tsrowd\sqformat\trbrdrt\brdrnone\trbrdrb\brdrnone\trbrdrl\brdrnone\trbrdrr\brdrnone\trbrdrh\brdrnone\trbrdrv\brdrnone\trgaph0\clpadft3\clpadt75\clpadfr3\clpadr75\clpadfl3\clpadl0\clpadfb3\clpadb0\tsvertalt\ltrch\i0\b0\strike0\ulnone\sl276\slmult1\sa180 TableNormal;}{\*\ts3\tsrowd\sbasedon2\sqformat\trbrdrt\brdrs\brdrw15\brdrcf0\trbrdrb\brdrs\brdrw15\brdrcf0\trbrdrl\brdrs\brdrw15\brdrcf0\trbrdrr\brdrs\brdrw15\brdrcf0\trbrdrh\brdrs\brdrw15\brdrcf0\trbrdrv\brdrs\brdrw15\brdrcf0\trgaph0\clpadft3\clpadt75\clpadfr3\clpadr75\clpadfl3\clpadl0\clpadfb3\clpadb0\tsvertalt\ltrch\i0\b0\strike0\ulnone\sl240\slmult1 TableGrid;}{\s0\sqformat\ltrch\i0\b0\strike0\ulnone\sl276\slmult1\sa180 Normal;}{\*\cs4\additive\sqformat\ltrch\i0\b0\strike0\cf2\ulc2\ul Hyperlink;}}\nouicompat\viewkind1\paperw12240\paperh15840\margl1425\margr1425\margt1425\margb1425\deftab720\sectd\pgwsxn12240\pghsxn15840\marglsxn1425\margrsxn1425\margtsxn1425\margbsxn1425\headery720\footery720\pard\s0\ltrpar\sl276\slmult1\sa180{\ltrch\i0\b0\strike0\ulnone\par}}

    Note that this solution would work for empty documents. It is not possible to remove the styles from non-empty documents, as this will cause them to appear incorrectly or even to a failure to load them.

    Other than that, the only option to restrict the size of the exported document would be to implement your own RtfFormatProvider in the way you find appropriate.


    Regards,
    Iva Toteva
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. UI for WPF is Visual Studio 2017 Ready
  4. Marc
    Marc avatar
    2 posts
    Member since:
    Jul 2012

    Posted 11 Jul 2012 Link to this post

    That's what happens when you try to save RTF in databases that are not meant for it I guess. I'll look into creating our own provider to see if I can make it work.

    Thanks for you help.
  5. Chethan
    Chethan avatar
    2 posts
    Member since:
    Oct 2012

    Posted 26 Apr 2013 Link to this post

    Hi Telerik, 

    Even we were facing the similar issue mentioned by Marc.
    We have thin client and thick client application for our product, for which we have a common DB.
    In Thin-Client we are using Telerik and in Thick-Client we are using Traditional RichText Box used in windows application.

    So when we save any Rich Text in Thin client and open the same in Thick client, we see string "1425" prefixed to the original Rich Text.
    And if we save any simple text in Thick Client, the result will have around 300 characters, whereas if we save same text from Thin-Client it will have 4000 chars.
    We are using 2012.3.1129.1050 version.

    I tried the solution provided by you to remove the styles. 
    I added these lines in editor_loaded event.
    But, just after removing any style from StyleRepository, for the next loop I get an InvalidOperationException saying "Collection was modified; enumeration operation may not execute." 

    How to fix it? Am I missing anything?
    Is there any way to disable these headers/footers to be populated or to get the traditional Rtf ?
    And, I also wanted to know how to create our own rtfFormatProvider?

    Thanks in advance.
    Chethan
Back to Top