Wonder if this possible. Saw many posts on adding watermark after the pdf is created and saved in disk. But during creation of document how do i add a image watermark. I know how to add a image to document. But how do i position it such that it comes at the end of page.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Carriage Return (ASCII chr 13) is missing from tex
- Why am I getting UnauthorizedAccessException on th
- Correctly parse PDF paragraphs with Python
This is essentially identical to adding a header or footer.
You need to create a class that implements
PdfPageEvent
, and in theOnPageEnd
, grab the page's PdfContentByte, and draw your image there. Use an absolute position.Note: You probably want to derive from PdfPageEventHelper, it has empty implementations of all the page events, so you just need to write the method you actually care about.
Note: Unless your image is mostly transparent, drawing it on top of your page will cover up Many Things. IIRC ("If I Recall Correctly"), PNG and GIF files added by iText will automatically be properly masked, allowing things under them to show through.
If you want to add an opaque image underneath everything, you should override
OnStartPage()
instead.This is Java, but converting it is mostly a matter of capitalizing method names and swapping get/set calls for property access.
For C#, use this code...