简体   繁体   中英

add header to pdf using iText

我如何使用iText 5.0.5为每个PDF页面添加标题。

This is covered in chapter 5 of iText In Action, 2nd ed . The code examples are all freely available online. In particular MovieCountries1 and MovieHistory2 both deal with page headers and footers.

It boils down to using a PdfPageEvent implementation (usually derived from PdfPageEventHelper to cut down on boilerplate) to draw into the page's Direct Content during an EndPage (or BeginPage I suppose) event.

You have to know where you want them, and you have to draw using a PdfContentByte instance, so you can't use the high-level Paragraph/Chapter/Chunk/Image/etc classes. You have to draw-this-there, draw-that-here. ColumnText can help a bit... but only for Plain Text. Anything even remotely fancy and you're on your own.

See the below link having video to show you.

http://itextpdf.com/book/chapter.php?id=4

For Header-Footer: http://kuujinbo.info/cs/itext.aspx

http://www.codeproject.com/KB/graphics/ITextSharpHelperClass.aspx

Please Vote if this helps to you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM