【问题标题】:MigraDoc/PDFSharp TextFrame Centre AlignMigraDoc/PDFSharp TextFrame 居中对齐
【发布时间】:2016-11-02 13:44:51
【问题描述】:

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

这是我目前拥有的

这就是我想要实现的目标

以下是我使用 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 };
}

【问题讨论】:

  • 你能发布一些代码吗?您使用哪种语言?您是否尝试过垂直对齐而不是水平对齐,因为您将其旋转了 90°?!

标签: pdfsharp migradoc


【解决方案1】:

这是一个应该可以工作的代码示例。

您可以使用TextFrame 的MarginLeft 属性将其移动到列的中间。

// Create the table 
Table Table = section.AddTable();
Table.Borders.Width = 0.5;

// create 3 columns
Column column1 = Table.AddColumn("4cm");
Column column2 = Table.AddColumn("4cm");
Column column3 = Tabl.AddColumn("4cm");


// make the row
Row row = Table.AddRow();


for (int i = 0; i < 3; i++)
{
    TextFrame t = row.Cells[i].AddTextFrame();
    t.Orientation = TextOrientation.Upward;
    t.Height = new Unit(140);

    // set the left margin to half of the column width
    t.MarginLeft = this.Tabelle.Columns[i].Width/2;

    Paragraph p = new Paragraph();
    p.Format.Alignment = ParagraphAlignment.Center;       
    p.AddText("Test_" + i.ToString());

    t.Add(p);
}

这会产生以下输出:

【讨论】:

  • 这没有影响。
  • @ccStars 我找到了。请参阅编辑。希望对你有帮助
  • @ccStars 我是否过度阅读了您问题中的包装部分?或者你所说的“包裹”是什么意思?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-23
  • 2017-01-06
相关资源
最近更新 更多