Hi ,
Is anybody tried to create Pdf file from aspx page..?
meanse I want to place controls such as textbox , buttons and whatever displayed after page runs that on pdf page.
I am trying it by using iTextSharp dll I am giving my code here ..
the file is created but it gives me error that the file is damaged coluld not opened
and I have not found any headerfooter to place in its footer property
[code]
protected void Button2_Click(object sender, EventArgs e)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-desposition", "attachment;filename=FileName.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
System.IO.StringWriter stringWr = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWritr = new HtmlTextWriter(stringWr);
PlaceHolder1.RenderControl(htmlWritr);
StringReader reader = new StringReader(stringWr.ToString());
Document doc = new Document(PageSize.A4);
HTMLWorker parser = new HTMLWorker(doc);
PdfWriter.GetInstance(doc, Response.OutputStream);
doc.Open();
try
{
parser.Parse(reader);
}
catch (Exception ex)
{
Paragraph paragraph = new Paragraph("Error! " + ex.Message);
paragraph.SetAlignment("center");
Chunk text = paragraph.Chunks[0] as Chunk;
if (text != null)
{
}
doc.Add(paragraph);
}
finally
{
//doc.Close();
}
}
public override void VerifyRenderingInServerForm(Control control)
{
}
[/code]
Please give me some link or any source code which is successfully generating pdf
Happy Programming!!
Rohi