2
votes

Ok, so I have a RichTextBox user control in which the user can enter any number of Rich Text elements which then converts the contents to HTML. At the moment, I am working on tables specifically. For the most part, they work pretty easily, but when I try to save the RTF to a file and then load it again, the \trautofit1 control word disappears and the table width is reduced.

To save to an RTF file, I'm using: TextRange.Save(fileStream, DataFormats.Rtf); I'm pretty sure the issue comes with how the RTF is saved, because the file that results from this has the shrunken table as well.

Here is the table before the save: Good Table

Here is the table after the save and load: Bad Table

So the question: Is there anyway in which to counter this behavior, or is there a better way to get the RTF, or should I be using a different control word to autosize the width of the table?

2

2 Answers

0
votes

Ok, well I found a solution but it isn't exactly what I was looking for. What brought about the decision to go this route was that this is how Word does it. When you go to create the table, I find the size of the RichTextBox, then divide it by the number of columns, then I explicitly set the width of each column with \cellx. Not the pretty solution I was looking for, but it works.

0
votes

I used another hack solution, before saving data I change columns width:

if (table != null && table.Columns.Count == 2)
{
    table.Columns[0].Width = new GridLength(200);
    table.Columns[1].Width = new GridLength(200);
    document.Blocks.Add(table);
}