4
Answers

Add logo image for each page on pdf file by iTextSharp

Hi there, hope in your help.
 
I have been trying to add an image to all pages using iTextSharp.
 
The below code correctly it inserted all information from asp Panel "on Print" but only inserts an image in the first page.
 
Is there any way to insert the image in the same way in all pages?
 
Can you help me ?
 
Thank you in advance.
  1. private void CreatePdf()  
  2.     {  
  3.         Response.ContentType = "application/pdf";  
  4.         Response.AddHeader("content-disposition""attachment;filename="test.pdf");  
  5.         Response.Cache.SetCacheability(HttpCacheability.NoCache);  
  6.   
  7.         StringWriter sw = new StringWriter();  
  8.         HtmlTextWriter hw = new HtmlTextWriter(sw);  
  9.   
  10.         pnPrint.RenderControl(hw);  
  11.   
  12.         StringReader sr = new StringReader(sw.ToString());  
  13.         string imagepath = Server.MapPath(".") + "\\Img\\logo.jpg";  
  14.   
  15.         Document pdfDoc = new Document(PageSize.A4, 20f, 20f, 10f, 20f);  
  16.   
  17.         try  
  18.         {  
  19.             HTMLWorker htmlparser = new HTMLWorker(pdfDoc);  
  20.             PdfWriter.GetInstance(pdfDoc, Response.OutputStream);  
  21.             pdfDoc.Open();  
  22.   
  23.             for (int i = 0; i < 5; i++)  
  24.             {  
  25.                 Image image = Image.GetInstance(imagepath);  
  26.                 image.Alignment = Image.ALIGN_LEFT;  
  27.                 pdfDoc.Add(image);  
  28.                 htmlparser.Parse(sr);  
  29.             }  
  30.         }  
  31.         catch (Exception ex)  
  32.         {  
  33.             throw ex;  
  34.         }  
  35.         finally  
  36.         {  
  37.             pdfDoc.Close();  
  38.             Response.End();  
  39.         }  
  40.     }  
 
Answers (4)
1
Manas Mohapatra

Manas Mohapatra

NA 29.3k 3.3m 7y
If you want to display email notification in user system, then I am not sure you can achieve that. Because it is user system and you can't do any change through WebApp. 
 
If you want to display notification in web application to user then you can achieve it.
 
0
sameer shaikh

sameer shaikh

NA 172 8k 7y
 Thanks guys
 
Regards
Sameer shaikh 
0
Sameer Shaik

Sameer Shaik

NA 953 1k 7y
As Ramesh said, its not in your hand. its not logical.  
0
Ramesh Palanivel

Ramesh Palanivel

NA 9.5k 138.6k 7y
Hi Sameer,
 
Thats what I am saying, You cannot do it in your coding.. It have to be configured in their mail settings.
 
 
0
sameer shaikh

sameer shaikh

NA 172 8k 7y
@Rakesh
 
sorry, Actually i didn't mention one thing i have User table that contain list of users and am going to send email to all.
 
if end users gmail/hotmail account is open,show him notification,
 
can i achive this kind of logic at my side i.e using coding.
 
Regards
Sameer Shaikh 
 
 
 
 
0
Ramesh Palanivel

Ramesh Palanivel

NA 9.5k 138.6k 7y
Hi Sameer,
 
 
I think you cannot achieve this in from your end. It has to be configured in receiver mail settings. 
 
You can send the mail to any mail services, which mean it may be an Yahoo,gmail or rediffmail whatever may be...
 
The mail receive notification wants to be configured in their mail settings.