代码之家  ›  专栏  ›  技术社区  ›  ccStars

MigraDoc/PDFSharp文本框中心对齐

  •  1
  • ccStars  · 技术社区  · 9 年前

    我正在使用文本框内的段落,以使文本方向向上显示。这几乎是我希望的方式,我得到的最后一个问题是文本似乎是左对齐的,我尝试将段落对齐设置为居中。这没有任何影响,也看不到使用文本框进行此操作的选项。输出的文本不会每次都相同。

    这就是我目前拥有的

    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 回复  |  直到 9 年前
        1
  •  3
  •   Mong Zhu Bart de Boer    9 年前

    下面是一个代码示例。

    您可以使用 MarginLeft 财产 TextFrame

    // 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