Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

CSS to grid exported to PDF using iTextSharp

2010-02-10
2013-05-01
  • 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