MigraDoc / PDFSharp TextFrame中心对齐

时间:2016-11-02 13:44:52

标签: pdfsharp migradoc

我在TextFrame中使用Paragraph来获取向上显示的文本方向这几乎是我想要的方式,我得到的最后一个问题是文本似乎是左对齐,我试过将段落对齐设置为中心,这没有任何影响,也看不到使用TextFrame执行此操作的选项。每次输出的文字都不一样。

这就是我目前所拥有的

enter image description here

这就是我想要实现的目标

enter image description here

以下是我用来使用MigraDoc实现此目的的代码

for (int i = 0; i < section2Items.Length; i++)
{
    TextFrame colXTextFrame = bothSection2ItemHeadersRow.Cells[i + 1].AddTextFrame();
    colXTextFrame.Orientation = TextOrientation.Upward;
    colXTextFrame.Height = new Unit(140);

    Paragraph colXParagraph = new Paragraph();
    colXParagraph.Format.Alignment = ParagraphAlignment.Center;
    colXParagraph.AddText(section2Items[i].Section2ItemTitle);
    colXTextFrame.Add(colXParagraph);

    bothSection2ItemHeadersRow.Cells[i + 1].Borders.Bottom = new Border() { Color = new MigraDoc.DocumentObjectModel.Color(255, 255, 255), Width = new MigraDoc.DocumentObjectModel.Unit(0), Style = MigraDoc.DocumentObjectModel.BorderStyle.None };
}

1 个答案:

答案 0 :(得分:3)

这是一个应该有效的代码示例。

您可以使用MarginLeft的{​​{1}}属性将其移到列的中间位置。

TextFrame

这会产生以下输出:

enter image description here