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.
- private void CreatePdf()
- {
- Response.ContentType = "application/pdf";
- Response.AddHeader("content-disposition", "attachment;filename="test.pdf");
- Response.Cache.SetCacheability(HttpCacheability.NoCache);
-
- StringWriter sw = new StringWriter();
- HtmlTextWriter hw = new HtmlTextWriter(sw);
-
- pnPrint.RenderControl(hw);
-
- StringReader sr = new StringReader(sw.ToString());
- string imagepath = Server.MapPath(".") + "\\Img\\logo.jpg";
-
- Document pdfDoc = new Document(PageSize.A4, 20f, 20f, 10f, 20f);
-
- try
- {
- HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
- PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
- pdfDoc.Open();
-
- for (int i = 0; i < 5; i++)
- {
- Image image = Image.GetInstance(imagepath);
- image.Alignment = Image.ALIGN_LEFT;
- pdfDoc.Add(image);
- htmlparser.Parse(sr);
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- finally
- {
- pdfDoc.Close();
- Response.End();
- }
- }