I'm trying to create a two column RTF file which seems to be ok, but the second column usually contains (not all the time) content on Asian languages. Some of these languages are not using any word separator (like space) and this is what causes me issues. As the text doesn't have any separator the line is never split, so the column width is increased and the first column gets squished. Did anyone faced with this issue?
How can I create a perfectly (50-50%) equal two column RTF table where the text is auto wrapped/split?
I tried to set preferred width like this:
PreferredWidth.FromPercent(50);
Which seems to work for short lines... but as soon as a line gets longer then the column width it starts to mess up the column widths.
I also tried to set WrapText to true, but that doesn't really helped at all.
In your case you should use fixed column width. For example the following code demonstrates the technique: first calculate page width, then explicitly specify cell width in the table and finally use fixed column width auto-fit behavior:
string longStringWithoutSpaces = @"TestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTest";
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Calculate visible width.
PageSetup ps = builder.PageSetup;
double contentWidth = ps.PageWidth - ps.LeftMargin - ps.RightMargin;
Table table = builder.StartTable();
builder.InsertCell();
// Explicitely specify widht of cell.
builder.CellFormat.Width = contentWidth / 2;
builder.Write(longStringWithoutSpaces);
builder.InsertCell();
builder.CellFormat.Width = contentWidth / 2;
builder.Write(longStringWithoutSpaces);
builder.EndRow();
builder.EndTable();
// Use fixed column widht autofit behaviour.
table.AutoFit(AutoFitBehavior.FixedColumnWidths);
doc.Save(@"C:\Temp\out.rtf");