Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello, I want to print a panel with formatting and images.

The CSS is specified in style.css


When I print using this code, no style or image is there. Just a plain pdf with text. Now, I need style and images. How to do?
C#
protected void btn_print_Click(object sender, EventArgs e)
   {
       Response.ContentType = "application/pdf";
       Response.AddHeader("content-disposition", "attachment;filename=Panel.pdf");
       Response.Cache.SetCacheability(HttpCacheability.NoCache);
       StringWriter sw = new StringWriter();
       HtmlTextWriter hw = new HtmlTextWriter(sw);
       pnl_print.RenderControl(hw);
       StringReader sr = new StringReader(sw.ToString());
       Document pdfDoc = new Document(iTextSharp.text.PageSize.A4, 10f, 10f, 100f, 0f);
       HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
       PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
       pdfDoc.Open();
       htmlparser.Parse(sr);
       pdfDoc.Close();
       Response.Write(pdfDoc);
       Response.End();
   }
Posted
Updated 6-Apr-15 23:31pm
v2
Comments
ramyajaya 7-Apr-15 8:32am    
You can change the content as html and write html tags in response. write

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