I have used the following code after adding the itext.dll in the bin folder
//Get the HTML from GridView1
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView1.RenderControl(htw);
string html = "<html><body>" + sw.ToString() + "</body></html>";
//Set up the response
Response.Clear();
Response.ContentType = "application/pdf";
//Create pdf document
Document document = new Document(PageSize.A4, 80, 50, 30, 65);
//Create pdf writer, output directly to OutputStream
PdfWriter writer = PdfWriter.GetInstance(document, Response.OutputStream);
document.Open();
//Create tempfile to hold the HTML:
string tempFile = Path.GetTempFileName();
using (StreamWriter tempwriter = new StreamWriter(tempFile, false))
{
tempwriter.Write(html);
}
//Parse the HTML into the document
HtmlParser.Parse(document, tempFile);
//Clean ...
Go to the complete details ...