2

我有一个 HTML 表单,其中包含标签和文本框。

填写此表格后,将其导出为 PDF。

导出所有标签文本。但文本框文本不会导出为 PDF。

代码

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();
}

为什么文本框文本没有导出为 PDF?

4

2 回答 2

1

我认为,当您进行渲染时,divToPDF您会得到一个新的 html 并且它没有页面上填充的值。您可能想要查看使用divToPDFis 您想要查看访问InnerHtmlorOuterHtml属性并使用它。

于 2013-02-14T19:56:32.803 回答
0

尝试这个。

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);
}
于 2013-02-17T06:33:28.833 回答