Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add header to pdf using iText

Tags:

java

itext

how i can add header to each PDF page using iText 5.0.5.

like image 732
pdfgf Avatar asked Dec 01 '22 08:12

pdfgf


2 Answers

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.

like image 149
Mark Storer Avatar answered Dec 02 '22 23:12

Mark Storer


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.

like image 21
Yoko Zunna Avatar answered Dec 02 '22 23:12

Yoko Zunna