Click here to Skip to main content
15,885,899 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi, I have this PDF export method. I wanted to add watermarking text as the background. Anyone can help me? Thank you.

private void ExportGridToPDF()
               {

                   username = (string)(Session["username"]);
                   Response.ContentType = "application/pdf";
                   Response.AddHeader("content-disposition", "attachment;filename=" +
                                   username + "'s Purchase.pdf");
                   Response.Cache.SetCacheability(HttpCacheability.NoCache);
                   StringWriter sw = new StringWriter();
                   HtmlTextWriter hw = new HtmlTextWriter(sw);
                   //gv_CartProduct.DataBind();


                   gv_CartProduct.RenderControl(hw);
                   //gv_CartProduct.HeaderRow.Style.Add("width", "15%");
                   //gv_CartProduct.HeaderRow.Style.Add("font-size", "10px");
                   //gv_CartProduct.Style.Add("text-decoration", "none");
                   //gv_CartProduct.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
                   //gv_CartProduct.Style.Add("font-size", "8px");


                   StringReader sr = new StringReader(sw.ToString());
                   string str = "<h1 title=’Header’ align=’Center’> Thank You "
                                  +  username + ", for shopping at
                                   ShopNow</h1><br><table
                                    align=’Center’><tr><td
                                    style=’width:100px;color:green’> You have made
                                    successful payment at ShopNow online shop. Please
                                    keep this invoice. Thank
                                   You</td></tr></table>";
                   StringReader sr1 = new StringReader(str);
                   Document pdfDoc = new Document(PageSize.A4, 7f, 7f, 7f, 0f);
                   HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
                   PdfWriter.GetInstance(pdfDoc, Response.OutputStream);


                   pdfDoc.Open();
                   htmlparser.Parse(sr1);
                   htmlparser.Parse(sr);
                   ConfirmPurchase();


                   pdfDoc.Close();
                   Response.Write(pdfDoc);



               }
Posted
Comments
Sinisa Hajnal 3-Feb-15 6:10am    
What have you tried?
Member 11237565 3-Feb-15 6:52am    
Tried itextshape. but couldn't get it working. Doesn't know why.

1 solution

You can refer to this codeproject article PDF File Writer C# Class Library (Version 1.11.0)[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900