2016-11-02 31 views
0

我正在使用TextFrame中的段落来获取文本方向,以便向上显示,这正在努力使我近乎如何我最终的问题是文本似乎是左对齐,我已经尝试将段落对齐设置为居中,这没有任何影响,并且看不到使用TextFrame执行此操作的选项。输出的文本每次都不一样。MigraDoc/PDFSharp TextFrame中心对齐

这是我目前有

enter image description here

这是我想acheive

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 }; 
} 
+0

你可以发布一些代码?你使用哪种语言?你是否尝试过垂直对齐而不是水平对齐,因为你把它转过90°?! –

回答

2

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

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

// 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); 
} 

这将产生以下输出:

enter image description here

+0

这没有影响。 – ccStars

+0

@ccStars我找到了。请参阅编辑。希望它有帮助 –

+0

@ccStars我是否重读了你的问题中的包装部分?或者你认为什么是“包装”? –