将模态对话框窗口转换为pdf

时间:2017-06-29 11:37:40

标签: c# asp.net pdf itext

我尝试使用iTextSharp将带有3个DataTables的模态对话框转换为pdf:

DataTable dtTable = (DataTable)ViewState["LoanPlan"];
DataTable dtTax = (DataTable)ViewState["PlanTaxData"];
DataTable dtPlan = (DataTable)ViewState["PlanAllData"];

我使用此代码尝试完成它:

protected void buttonPDF_Click(object sender, EventArgs e)
{
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-disposition", "attachment;filename=TestPage.pdf");
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);
    this.RenderControl(hw);
    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();
    htmlparser.Parse(sr);
    pdfDoc.Close();
    Response.Write(pdfDoc);
    Response.End();
}

但似乎它实际上试图将整个.aspx页面转换为.pdf格式。我应该如何仅针对模态对话或仅仅针对3个DataTables?

0 个答案:

没有答案