Click here to Skip to main content
14,981,856 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I am exporting html to pdf and this work fine but the style applied to my html is missing on the pdf document.

This is the code I am using:
 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["ID"] != null)
            {
                try
                {
                    _orderinfo.OrderId = Convert.ToString(Request["ID"]);
                    OrderId = Request["ID"].ToString();
                    DataSet ds = _orderinfo.getOrderDetailsById();
                    DateTime today = DateTime.Today;
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        string OrderReport = string.Format("<table><tr><td style='width: 475px;'><span style='color: firebrick;font-weight: bold;'>Hello</span></td><td></td><td>INVOICE</td></tr>");
                        OrderReport += string.Format("<tr><td><span style='color: firebrick;font-weight: bold;'>MarketPlace</span></td><td></td><td>Invoice #..............</td></tr>");
                        OrderReport += string.Format("<tr style='height:50px;'><td>TO:</td><td>SHIP TO:</td><td></td></tr>");
                        OrderReport += string.Format("<tr><td>{0}</td><td>{1}</td><td></td></tr>", dr["UserName"], dr["UserName"]);
                        OrderReport += string.Format("<tr style='height:100px;'><td><span style='text-transform:uppercase;'>Comments </span></td><td></td><td></td></tr>");
                        OrderReport += string.Format("<tr style='height:10px;'><td></td><td></td><td></td></tr></table>");
                        OrderInvoice.Text += OrderReport;

                    }
                }
                catch (Exception ex)
                {
                    Response.Write(ex.ToString());
                }
            }
            
        }
 protected void ExportPDF_Onclick(object sender, EventArgs e)
    {
        try
            {
                
                Response.ContentType = "application/pdf";
                Response.AddHeader("content-disposition", "attachment;filename=OrderDetails.pdf");
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                StringWriter sw = new StringWriter();
                HtmlTextWriter tw = new HtmlTextWriter(sw);
                this.Page.RenderControl(tw);
                StringReader sr = new StringReader(sw.ToString());
                Document Orderpdf = new Document(PageSize.A4, 10f, 10f, 50f, 0.0f);
                HTMLWorker htmlparser = new HTMLWorker(Orderpdf);
                PdfWriter.GetInstance(Orderpdf, Response.OutputStream);
                Orderpdf.Open();
                htmlparser.Parse(sr);
                Orderpdf.Close();
                Response.Write(Orderpdf);

                Response.End();
            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString());
            }
        
    }
Can some help telling me why the style is not applied to the pdf document.
Posted
Updated 31-May-13 12:50pm
v4
Comments
AlphaDeltaTheta 1-Jun-13 3:10am
   
itext simple html parser?? this doesn't honor much css as you will expect. Create the layout in Document.
El Dev 1-Jun-13 12:14pm
   
you mean editor page(html page)??

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