2016-11-02 35 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我是否重讀了你的問題中的包裝部分?或者你認爲什麼是「包裝」? –