C# Exporting Webform to PDF using ITextSharp

  • Thread starter Thread starter vinisha9
  • Start date Start date
V

vinisha9

Guest
I have a webform with data entry fields like attached image. I am trying to use ITextsharp to export this form to pdf but the textbox values and dropdownlist selection is not reflecting in the pdf. can anyone please sujject me how to export the textbox and dropdownlist values to pdf. Below is the code i am using.


Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=AppraisalForm.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
this.Page.RenderControl(hw);
//divmain.InnerHtml

StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);

HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);

pdfDoc.Open();

List<IElement> elements = HTMLWorker.ParseToList(new StringReader(sw.ToString()), null);

foreach (IElement el in elements)
{
pdfDoc.Add(el);

}

pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();




1513608.png

Continue reading...
 
Back
Top