Hi, This is sailaja. I've been trying to create watermark in PDF using 
itextsharp. i found code in few sites. finally i'm able to create watermark. 
but the problem is i added a table with background color to PDF. And the 
watermark was overwritten by table header. please have a look at attached pdf, 
then you can understand my issue. I'm using the following code. 

public partial class Footer : PdfPageEventHelper
    {
        public static string HeaderText;
        public override void OnEndPage(PdfWriter writer, 
iTextSharp.text.Document doc)
        {
            PdfContentByte under = writer.DirectContentUnder;
            BaseFont baseFont = BaseFont.CreateFont(BaseFont.HELVETICA, 
BaseFont.WINANSI, BaseFont.EMBEDDED);
            PdfGState gstate = new PdfGState();
            gstate.FillOpacity=0.3f;
            gstate.StrokeOpacity=0.3f;
            under.SaveState();
            under.SetGState(gstate);
            under.BeginText();
            under.SetColorFill(BaseColor.RED);
            under.SetFontAndSize(baseFont, 60);
            under.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "JAZZ 
PHARMACEUTICALS", 400, 280, 45);
            under.EndText();
            under.RestoreState();

            Paragraph footer = new Paragraph("Footer Text", 
FontFactory.GetFont(FontFactory.TIMES, 9, iTextSharp.text.Font.NORMAL));
            footer.Alignment = Element.ALIGN_RIGHT;
            PdfPTable footerTbl = new PdfPTable(1);
            footerTbl.TotalWidth = 1000;
            footerTbl.HorizontalAlignment = Element.ALIGN_RIGHT;
            PdfPCell cell = new PdfPCell(footer);
            cell.Border = 0;
            cell.PaddingLeft = 0;
            footerTbl.AddCell(cell);
            footerTbl.WriteSelectedRows(0, -1, 25, 30, writer.DirectContent);
        }
    }

In Controller:
 iTextSharp.text.Document document = new 
iTextSharp.text.Document(PageSize.LETTER.Rotate(), 8, 8, 10, 25);
                PdfWriter writer = 
iTextSharp.text.pdf.PdfWriter.GetInstance(document, output);
                PdfDestination pdfDest = new PdfDestination(PdfDestination.XYZ, 
0, document.PageSize.Height, 1f);
                document.Open();
                JazzIC.Models.Footer.HeaderText = "ScoreCard-All Territories";
                writer.PageEvent = new Footer();

                iTextSharp.text.pdf.PdfPTable dataTable = new PdfPTable(new 
float[13] { 1.2f, 1.8f, 1.4f, 1.4f, 1.2f, 1.2f, 1.2f, 1.2f, 1.3f, 1.5f, 1.5f, 
1.5f, 1.2f });

//code add rows to datatable
                document.Add(dataTable);

                PdfAction action = PdfAction.GotoLocalPage(1, pdfDest, writer);
                writer.SetOpenAction(action);
                writer.CloseStream = false;
                document.Close();
                output.Position = 0;
              //  return File(output.ToArray(), "application/pdf", 
string.Format("AllTerritoriesHO{0}.pdf", DateTime.Now.ToString("ddMMMyyyy")));
                return 
(HttpContext.Request.UserAgent.ToLower().Contains("ipad") == true ? 
File(output.ToArray(), "application/pdf") : File(output.ToArray(), 
"application/pdf", string.Format("AllTerritoriesHO{0}.pdf", 
DateTime.Now.ToString("ddMMMyyyy"))));


And also i'm exporting few graphs as images which are also overriding Watermark 
text.

Please suggest me the solution.

Thanks in advanced.
Sailaja

Attachment: ScoreCard2013.pdf
Description: Adobe PDF document

------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnnow-d2d
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to