Migra Doc PDF页脚样式
问题描述:
我有一个页脚在每个页面的左侧和右侧。页脚中的每个段落都包含2行文字。我想要的是在页脚的两行文字之间添加一条水平线。Migra Doc PDF页脚样式
这里是添加页脚的代码。
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);
}
这里是所需页脚结果的图片。
答
我得到这个想通我自己。 创建一个包含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);