I suggest you use the page event:
myWriter.setPageEvent(new BackgroundPageEvent(backgroundImage));
class BackgroundPageEvent extends PdfPageEventHelper {
Image backgroundImage = null;
public BackgroundPageEvent( Image img ) {
backgroundImage = img;
}
public void onStartPage(PdfWriter writer, Document doc) {
PdfContentByte underContent = writer.getDirectContentUnder();
underContent.addImage(backgroundImage);
}
}
With the above code backgroundImagewill be added to the "under the content" when creating each page. No need to worry about when to add it yourself ... iText will consider this for you, and the first thing in underContent of each page will be your image. You may need to play around with various addImage overrides to get the right size.
, doc , . , , , / (, , ).
PdfPageEvent , . PdfPageEventHelper "no ops", [s], :
- OnStartPage
- OnEndPage
- OnCloseDocument
- OnParagraph
- OnParagraphEnd
- OnChapter
- OnChapterEnd
- OnSection
- OnSectionEnd
- OnGenericTag
Handy. () , , OnGenericTag rect, , . .