C# Aspose RTF - 亚洲语言的列宽混乱

问题描述 投票:0回答:1

我正在尝试创建一个两列 RTF 文件,这似乎没问题,但第二列通常包含(并非总是)有关亚洲语言的内容。其中一些语言不使用任何单词分隔符(如空格),这就是导致我出现问题的原因。由于文本没有任何分隔符,因此行永远不会拆分,因此列宽会增加,并且第一列会被压扁。 有人遇到过这个问题吗

如何创建一个完美(50-50%)相等的两列 RTF 表,其中文本自动换行/分割?

我尝试像这样设置首选宽度: PreferredWidth.FromPercent(50);

这似乎适用于短行...但是一旦行变得比列宽长,它就开始扰乱列宽。

我也尝试将 WrapText 设置为 true,但这根本没有帮助。

c# word-wrap rtf aspose column-width
1个回答
0
投票

在您的情况下,您应该使用固定的列宽。例如,以下代码演示了该技术:首先计算页面宽度,然后在表格中显式指定单元格宽度,最后使用固定列宽自动调整行为:

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");

© www.soinside.com 2019 - 2024. All rights reserved.