首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MigraDoc/PDFSharp TextFrame中心对齐

MigraDoc/PDFSharp TextFrame中心对齐
EN

Stack Overflow用户
提问于 2016-11-02 13:44:51
回答 1查看 3K关注 0票数 2

我使用TextFrame中的一个段落将文本方向向上显示--这几乎是我想要的结果,我得到的最后一个问题是文本似乎是左对齐的,我尝试将段落对齐设置为中心--这没有影响,也看不到使用TextFrame的选项。每次输出的文本都不会相同。

这就是我现在所拥有的

这就是我想要的

下面是我使用MigraDoc来实现这个目标的代码

代码语言:javascript
复制
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 };
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-04 10:02:35

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

您可以使用TextFrameTextFrame属性在列的中间移动它。

代码语言:javascript
复制
// 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);
}

这将产生以下输出:

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40381515

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档