Reputation: 157
I have an HTML form, which contains lables and textboxes.
After filling this form, it is exported to PDF.
All the label Texts are exported. But the textbox text is not exported to PDF.
Code
protected void btnExportPDF_Click(object sender, EventArgs e)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=DecForm.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
this.divToPdf.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10, 10, 2, 10);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
}
Why are the textbox text not exported through to PDF?
Upvotes: 2
Views: 2762
Reputation: 9380
Try this.
List<IElement> elements = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(new StringReader(htmlString), null);
//htmlString is your form html
foreach (IElement el in elements)
{
pdfDoc.add(el);
}
Upvotes: 0
Reputation: 1719
I think that when you're rendering divToPDF
you are getting a fresh cut of the html and it does not have the values there were populated on the page. You may want to look at using the divToPDF
is you'll want to look at accessing the InnerHtml
or OuterHtml
property and use that.
Upvotes: 1