0

I am looking for repeating watermark at 45 degree angle on whole page from top to bottom as mentioned in below sample image.

I am using itextsharp and C#.

Sample Watermark image

Please help me with sample code.

mkl
  • 90,588
  • 15
  • 125
  • 265
  • What have you tried, how far did you get, what stopped you? – mkl Jun 10 '21 at 17:15
  • 1
    You might want to consider this question: https://stackoverflow.com/questions/2372041/c-sharp-itextsharp-pdf-creation-with-watermark-on-each-page?rq=1 and take the code in the answer for the watermark and put it inside a nested for loop, incrementing the `x` and `y` position until you've covered the page. – theKunz Jun 10 '21 at 17:38

1 Answers1

0
byte[] bytes = File.ReadAllBytes(@"D:\20.pdf");
Font blackFont = FontFactory.GetFont("Arial", 22, Font.NORMAL, BaseColor.LIGHT_GRAY);
using (MemoryStream stream = new MemoryStream())
{
    PdfReader reader = new PdfReader(bytes);
    using (PdfStamper stamper = new PdfStamper(reader, stream))
    {
        int pages = reader.NumberOfPages;
        for (int i = 1; i <= pages; i++)
        {

            iTextSharp.text.Rectangle pageRect = reader.GetPageSize(i);
            float currentPosY = pageRect.Height;
            float currentPosX = pageRect.Width;
            
            while(currentPosY>0)
            {
                while (currentPosX > 0)
                {
                    ColumnText.ShowTextAligned(stamper.GetUnderContent(i), Element.ALIGN_CENTER, new Phrase("sajids@rcjy.gov.sa", blackFont), currentPosX, currentPosY, 45);

                    currentPosX -= 150;
                }
                currentPosY -= 100;
                currentPosX = pageRect.Width;
            }                       
        }
    }
    bytes = stream.ToArray();
}
File.WriteAllBytes(@"D:\Test_1.pdf", bytes);
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103