我正在使用itextsharp創建pdf文件。我想爲pdf文檔中的每個頁面添加頁眉和頁腳。誰能告訴我我該怎麼做?如何使用C#中的iTextsharp版本5.2.0在pdf的所有頁面中添加頁眉和頁腳
我使用的是itext 5.2.0在此,我無法找到使用HeadeFooter類的選項,該選項在早期版本中可用。
在此先感謝..
我正在使用itextsharp創建pdf文件。我想爲pdf文檔中的每個頁面添加頁眉和頁腳。誰能告訴我我該怎麼做?如何使用C#中的iTextsharp版本5.2.0在pdf的所有頁面中添加頁眉和頁腳
我使用的是itext 5.2.0在此,我無法找到使用HeadeFooter類的選項,該選項在早期版本中可用。
在此先感謝..
對於iTextSharp的版本5+,頁眉/頁腳屬性已被刪除。現在可以通過我們的PageEventHandler
類來完成。雖然現在不是海峽,但好處是,現在你可以在頁眉和頁腳中添加更多的計劃文本。 Please check this link用於在iTextSharp中完成頭/頁腳等的完整鍛鍊。
請使用此代碼。
public partial class Footer : PdfPageEventHelper
{
public override void OnEndPage(PdfWriter writer, Document doc)
{
Paragraph footer= new Paragraph("THANK YOU", FontFactory.GetFont(FontFactory.TIMES, 10, iTextSharp.text.Font.NORMAL));
footer.Alignment = Element.ALIGN_RIGHT;
PdfPTable footerTbl = new PdfPTable(1);
footerTbl.TotalWidth = 300;
footerTbl.HorizontalAlignment = Element.ALIGN_CENTER;
PdfPCell cell = new PdfPCell(footer);
cell.Border = 0;
cell.PaddingLeft = 10;
footerTbl.AddCell(cell);
footerTbl.WriteSelectedRows(0, -1, 415, 30, writer.DirectContent);
}
}
請查看我的博客瞭解更多詳情 http://gopalkaroli.blogspot.in/2011/11/how-to-add-header-and-footer-on-pdf.html
怎麼樣一個頭? – divinediu 2014-04-25 10:36:07
要小心,當你標記技術,對您的問題。你不能在一個應用程序中使用所有的** C#**版本:)你有沒有看過這個** http://itextpdf.com/book/chapter.php?id=4 ** – 2012-04-17 15:04:39
更多的信息在這裏 - - http://stackoverflow.com/questions/2598917/itextsharp-is-missing-headerfooter-class或http://stackoverflow.com/questions/2321526/pdfptable-as-a-header-in-itextsharp – rt2800 2012-04-17 15:09:39