我想創建一個PDF頁腳。 我試過以下代碼在我的pdf文件中有頁腳。頁腳不顯示在pdf
private void AddFooter(string filephysicalpath, string documentname)
{
byte[] bytes = System.IO.File.ReadAllBytes(filephysicalpath);
Font blackFont = FontFactory.GetFont("Arial", 12, Font.NORMAL, BaseColor.BLACK);
using (MemoryStream stream = new MemoryStream())
{
PdfReader reader = new PdfReader(bytes);
using (PdfStamper stamper = new PdfStamper(reader, stream))
{
int pages = reader.NumberOfPages;
for (int i = 1; i <= pages; i++)
{
string footer = Convert.ToString(Session["Footer"]);
footer += "\n";
footer += documentname;
Phrase ph = new Phrase(footer);
Rectangle rect = new Rectangle(10f, 10f, 0);
ColumnText ct = new ColumnText(stamper.GetUnderContent(i));
ct.SetSimpleColumn(rect);
ct.AddElement(new Paragraph("line 1"));
ct.AddElement(new Paragraph("line 2"));
ct.Go();
// ColumnText.ShowTextAligned(stamper.GetUnderContent(i), Element.ALIGN_JUSTIFIED, new Phrase(ph), 8f, 5f, 0);
}
}
bytes = stream.ToArray();
}
System.IO.File.WriteAllBytes(filephysicalpath, bytes);
}
我沒有得到這個代碼的頁腳。
乍看起來沒問題,如果你使用'模子#GetOverContent(我)',它的文本還是顯示不出來? –
這永遠不能工作,因爲'新的矩形(10f,10f,0)'永遠不可能是一個適合你的文本的矩形。 –
我更改了代碼...... ColumnText ct = new ColumnText(stamper.GetUnderContent(i)); (新的詞組(新的詞組)(新的詞組(footer,FontFactory.GetFont(FontFactory.HELVETICA,12,Font.NORMAL))), 46,190,590,36,25,Element.ALIGN_LEFT | Element.ALIGN_BOTTOM); ct.Go();它給出正確的輸出,但它覆蓋到PDF文本我該如何解決問題 –