2017-10-15 101 views
0

我有一個頁腳在每個頁面的左側和右側。頁腳中的每個段落都包含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); 

    } 

這裏是所需頁腳結果的圖片。

enter image description here

回答

0

我得到這個想通我自己。 創建一個包含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);