【问题标题】:Migra Doc PDF Footer StylingMigra Doc PDF 页脚样式
【发布时间】:2017-10-15 12:03:13
【问题描述】:

我在每一页的左右都有一个页脚。页脚中的每个段落包含 2 行文本。我想要的是在页脚的两行文本之间添加一条水平线。

这是添加页脚的代码。

 private void AddFooterData(Section section) {
        // add prepared by. approved by etc

        var rightFooterSection = new Paragraph {
            Format = { Alignment = ParagraphAlignment.Right }
        };
        rightFooterSection.AddText("Prepared By Eng: " + _preparedBy);
        rightFooterSection.AddLineBreak();

        rightFooterSection.AddText("Page ");
        rightFooterSection.AddPageField();
        rightFooterSection.AddText(" / ");
        rightFooterSection.AddNumPagesField();
        section.Footers.Primary.Add(rightFooterSection);

        var date = DateTime.Now.ToString("yyyy/MM/dd");
        var leftSection = new Paragraph {
            Format = { Alignment = ParagraphAlignment.Left }
        };
        leftSection.AddText("Approved By: " + _approvedBy);

        leftSection.AddLineBreak();
        leftSection.AddText(date);
        section.Footers.Primary.Add(leftSection);

    }

这是所需页脚结果的图片。

【问题讨论】:

    标签: c# pdf report migradoc


    【解决方案1】:

    这是我自己想出来的。 创建一个包含 2 列的表格,其宽度与页面相同, 创建 2 行 在第一行,将底部边框设置为可见。 对齐每一行中的文本,因此左列将左对齐,右列将右对齐

    private void AddFooterData(Section section) {
    
            var rightFooterSection = new Paragraph {
                Format = { Alignment = ParagraphAlignment.Right }
            };
            rightFooterSection.AddText("Prepared By Eng: " + _preparedBy);
    
            var rightFooterPagePar = new Paragraph {
                 Format = { Alignment = ParagraphAlignment.Right }
             };
            rightFooterPagePar.AddText("Page ");
            rightFooterPagePar.AddPageField();
            rightFooterPagePar.AddText("/");
            rightFooterPagePar.AddNumPagesField();
    
    
            var date = DateTime.Now.ToString("yyyy/MM/dd");
            var leftSection = new Paragraph {
                Format = { Alignment = ParagraphAlignment.Left }
            };
            var leftDateSection = new Paragraph {
                Format = { Alignment = ParagraphAlignment.Left }
            };
            leftSection.AddText("Approved By: " + _approvedBy);
            leftDateSection.AddText(date);
            var footerTable = section.Footers.Primary.AddTable();
            var col1 = footerTable.AddColumn();
            col1.Width = "5.5in";
    
            var col2 = footerTable.AddColumn();
            col2.Width = "5.5in";
            var row1 = footerTable.AddRow();
            row1[0].Add(leftSection);
            row1[1].Add(rightFooterSection);
            row1.Borders.Bottom.Visible = true;
            row1.Borders.Bottom.Width = "0.10cm";
            var row2 = footerTable.AddRow();
            row2[0].Add(leftDateSection);
            row2[1].Add(rightFooterPagePar);
    

    【讨论】:

      猜你喜欢
      • 2013-06-06
      • 2011-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-20
      • 1970-01-01
      • 2018-11-01
      • 2013-02-09
      相关资源
      最近更新 更多