Change the width of "Product Description HSN HAC Code" Karthik Sir




 using (StringWriter sw = new StringWriter())
                {
                    using (HtmlTextWriter hw = new HtmlTextWriter(sw))
                    {
                        StringBuilder sb = new StringBuilder();
                        //Generate Invoice (Bill) Header.                   
                        sb.Append("<table style='width:10px;' border = '1'>");
                        sb.Append("<tr>");

                        //foreach (DataColumn column in dt2.Columns)
                        //{
                        //    sb.Append("<th style = 'width:40%;background-color: e7e7e7;color:#000000'>");
                        //    sb.Append(column.ColumnName);
                        //    sb.Append("</th>");
                        //}
                        for (int i = 0; i < dt2.Columns.Count; i++)
                        {
                            string width = i == 0 ? "'50px'" : "'20px'"; // first column will be 50% and others 20%
                            sb.Append("<th width=" + width + " style = 'background-color: #e7e7e7;color:#000000'>");
                            sb.Append(dt2.Columns[i].ColumnName);
                            sb.Append("</th>");
                        }

                        sb.Append("</tr>");
                        foreach (DataRow row in dt2.Rows)
                        {
                            for (int i = 0; i < dt2.Rows.Count; i++)

                            {
                                string width = i == 0 ? "'50%'" : "'20%'";
                                sb.Append("<tr>");
                                foreach (DataColumn column in dt2.Columns)
                                {
                                    sb.Append("<td  width=" + width + ">");
                                    sb.Append(row[column]);
                                    sb.Append("</td>");
                                }
                             
                                sb.Append("</tr>");
                            }
                        }
                     
                        sb.Append("</table>");

                        //Export HTML String as PDF.
                        StringReader sr = new StringReader(sb.ToString());
                        Document pdfDoc = new Document(PageSize.A3, 40f, 40f, 20f, 0f);
                        HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
                        PdfWriter writer = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
                        pdfDoc.Open();
                        htmlparser.Parse(sr);
                        pdfDoc.Close();
                        Response.ContentType = "application/pdf";
                        Response.AddHeader("content-disposition", "attachment;filename=Invoice_" + orderNo + ".pdf");
                        Response.Cache.SetCacheability(HttpCacheability.NoCache);
                        Response.Write(pdfDoc);
                        Response.End();
                    }
                }

Comments