Create Pdf from aspx page

Posted by Rohik under Regular Expressions on 7/16/2010 | Views : 6055 | Status : [Member] | Replies : 3
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



Responses

Posted by: Vikvish on: 7/18/2010 [Member] Starter

Up
0
Down
Hope this will help you..
Check the following Link

http://www.aspsnippets.com/Articles/Export-ASP.Net-GridView-to-PDF-with-Custom-Columns-Widths-using-iTextSharp.aspx

With Regards
Vikram

vikram

Rohik, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hanhnguyen239 on: 1/5/2012 [Member] Starter | Points: 25

Up
0
Down
I think your problem came from HTML code. Check if your HTML code has any error syntax. You can find the solution for this here. it may helpful.
http://hanhnguyen239.wordpress.com/2011/12/02/convert-html-to-pdf-in-asp-net/

Rohik, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Stevnetk on: 3/13/2012 [Member] Starter | Points: 25

Up
0
Down
Try this html to pdf converter: http://www.hiqpdf.com . With a single function call you can convert anything a browser can render. See the free demos and source code at: http://www.hiqpdf.com/demo/ConvertHtmlToPdf.aspx

Rohik, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response