Click here to Skip to main content
15,908,015 members

Comments by Monish Painter (Top 1 by date)

Monish Painter 19-Nov-12 2:34am View    
Having error in this line:
HtmlParser.Parse(Doc, xmlReader);
Have also added assemblies:
<pre lang="cs">using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;</pre>

Have also added iTextSharp.dll files in bin folder and added reference to the project.

<pre>protected void btngeneratePDF_Click(object sender, EventArgs e)
{

HtmlForm form = new HtmlForm();
form.Controls.Add(gvatt_report);
StringWriter sw = new StringWriter();
HtmlTextWriter hTextWriter = new HtmlTextWriter(sw);
form.Controls[0].RenderControl(hTextWriter);
string html = sw.ToString();
Document Doc = new Document();


PdfWriter.GetInstance
(Doc, new FileStream(Environment.GetFolderPath
(Environment.SpecialFolder.Desktop)
+ "\\monish.pdf", FileMode.Create));
Doc.Open();

Chunk c = new Chunk
("Export GridView to PDF Using iTextSharp \n",
FontFactory.GetFont("Verdana", 15));
Paragraph p = new Paragraph();
p.Alignment = Element.ALIGN_CENTER;
p.Add(c);
Chunk chunk1 = new Chunk
("By monish, monish@yahoo.com \n",
FontFactory.GetFont("Verdana", 8));
Paragraph p1 = new Paragraph();
p1.Alignment = Element.ALIGN_RIGHT;
p1.Add(chunk1);

Doc.Add(p);
Doc.Add(p1);

System.Xml.XmlTextReader xmlReader =
new System.Xml.XmlTextReader(new StringReader(html));
HtmlParser.Parse(Doc, xmlReader);

Doc.Close();
string Path = Environment.GetFolderPath
(Environment.SpecialFolder.Desktop)
+ "\\AmitJain.pdf";


ShowPdf(Path);

}
private void ShowPdf(string strS)
{
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.AddHeader
("Content-Disposition", "attachment; filename=" + strS);
Response.TransmitFile(strS);
Response.End();
Response.Flush();
Response.Clear();

}</pre>
Please can anyone get me the feasible solution for it as soon as possible??