Click here to Skip to main content
15,907,497 members

Comments by Swetha Bisa (Top 18 by date)

Swetha Bisa 24-Jul-13 10:10am View    
protected void btnpdf_Click(object sender, EventArgs e)
{
ExportToPdf(DivPDf, lblF.Text);

}
public void ExportToPdf(Control DivPDf, string fileName)
{


Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=" + fileName + ".pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
HtmlForm frm = new HtmlForm();
DivPDf.Parent.Controls.Add(frm);
frm.Attributes["runat"] = "server";
frm.Controls.Add(DivPDf);
frm.RenderControl(hw);
DivPDf.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0.0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
byte[] byteArr = Encoding.ASCII.GetBytes(sw.ToString());
MemoryStream stream = new MemoryStream(byteArr);
StreamReader stre = new StreamReader(stream);
pdfDoc.Open();
htmlparser.Parse(stre);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
}

public override void VerifyRenderingInServerForm(Control control)
{
/* Verifies that the control is rendered */
return;

}
these are the code snippets im using
Swetha Bisa 24-Jul-13 10:06am View    
ya its exporting to pdf but my problem is in pdf document im not getting the table which im getting in preview, im getting the labels scattered through out the page
Swetha Bisa 24-Jul-13 10:05am View    
hai sarin,

can u please let me know how the above mentioned code snippet is used??
Swetha Bisa 24-Jul-13 8:08am View    
hai sarin,

thanks for the reply, but i want to generate it as a salary slip, so how can i generate a pdf document.
Swetha Bisa 16-Jul-13 6:17am View    
hai prakash,

thanks for your reply but it dint help me... :(