I am creating pdf using itextsharp. Now I want to add watermark on each pages I tried method on
public override void OnStartPage(PdfWriter wr, iTextSharp.text.Document doc)
Now watermark is coming but if pdf page containing image then its hiding watermark
public class itsevent : PdfPageEventHelper
{
string watermarkText = string.Empty;
public itsevent(string watermark)
{
watermarkText = watermark;
}
public override void OnStartPage(PdfWriter wr, iTextSharp.text.Document doc)
{
float fontSize = 80;
float xPosition = 300;
float yPosition = 300;
float angle = 45;
PdfContentByte u = wr.DirectContentUnder;
PdfGState gs = new PdfGState();
u.SaveState();
u.SetGState(gs);
BaseFont baseFont =BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);
u.BeginText();
u.SetColorFill(iTextSharp.text.pdf.CMYKColor.LIGHT_GRAY);
u.SetFontAndSize(baseFont, fontSize);
u.ShowTextAligned(PdfContentByte.ALIGN_CENTER, watermarkText, xPosition, yPosition, angle);
u.EndText();
under.RestoreState();
}
}
itsevent ev = new itsevent("watermark");
pdfW.PageEvent = ev;
doc.Open();
Try using
GetOverContext()
to get the image https://simpledotnetsolutions.wordpress.com/2012/04/08/itextsharp-few-c-examples/