Hi,

Is there any way to directly obtain CSS for grid that is exported to PDF using iTextSharp? Right now, I am using the following code to generate a pdf. I haven't given CSS explicitly. I am directly exporting..  GridView is the grid I am exporting.  Grid in PDF is obtained but there is no CSS and even alignment is not proper.

Plz find the code below

MemoryStream m = new MemoryStream();
            Document document = new Document(PageSize.LETTER);

            StringWriter sw = new StringWriter();
            HtmlTextWriter hTextWriter = new HtmlTextWriter(sw);
            GridView.RenderControl(hTextWriter);
            string html = sw.ToString();
           
            Response.ContentType = "application/pdf";
            PdfWriter writer = PdfWriter.GetInstance(document, m);
            writer.CloseStream = false;

                        document.Open();

                        StringReader sr = new StringReader(html);
            XmlTextReader xtr = new XmlTextReader(sr);
            HtmlParser.Parse(document, xtr);
            xtr.Close();
            document.Close();
                        //  Write pdf bytes to outputstream
            Response.OutputStream.Write(m.GetBuffer(), 0, m.GetBuffer().Length);
            Response.OutputStream.Flush();
            Response.OutputStream.Close();
            m.Close();

Any answers would be greatly helpful.

Thanks,
Geetha