0

I have exported my grid view to PDF and it has exported successfully, but there is a minor problem in exported PDF! Although there is no extra space in my grid view, a lot extra space is exist in exported PDF file.Even there is no extra space on the top of the grid view. In other term, i have a one blank page and after that i have a logo and in the third page i have my context! Here is my cods:

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);
    pnlPerson.RenderControl(hw);
    StringReader sr = new StringReader(sw.ToString());
    Document pdfDoc = new Document(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();

Can any body help me?

Saeid
  • 1,996
  • 4
  • 27
  • 44
  • 1
    First, `HTMLWorker` has long been deprecated and replaced with `XMLWorker`, so I would strongly suggest you try switching to that. The former doesn't support CSS so that might be one of your problems. Second, PDF doesn't support HTML and iText isn't aware of ASP.Net things like `GridView`s. I say this so that you know that we need to see the actual HTML that you are passing into iText and asking it to attempt to translate to raw PDF commands for you. Whatever you pass in is the **only** thing that iText will attempt to parse. Anything that is a ".Net-ism" (like `~`) must be done by you first. – Chris Haas Feb 23 '14 at 15:22
  • Thank you so much for your suggestions, now would you mind give me more information about that, since i do not know anything about XML. That's why i chose the iTextSharp. – Saeid Feb 23 '14 at 16:26
  • Base solely on the names `HTMLWorker` and `XMLWorker` I can understand why many people actually pick the former. But the latter is also an HTML parser as long as it conforms to XHTML which ASP.Net is a giant supporter of. Check these out: http://stackoverflow.com/a/21165654/231316 http://stackoverflow.com/a/16105368/231316 http://stackoverflow.com/a/18206164/231316 http://stackoverflow.com/a/12181998/231316 – Chris Haas Feb 24 '14 at 13:48

0 Answers0