保存为pdf时不显示文本框

时间:2014-01-06 06:12:13

标签: c# asp.net .net pdf save

我正在开发一个asp.Net项目,需要以pdf格式保存。我需要根据数据库中的数据动态创建LabelTextBox 我的问题是,当我尝试将其保存为pdf时,只有TextBox丢失时才能保存标签。

以下是我创建Label& amp;的代码TextBox动态。

for (int i = 0; i < dt.Rows.Count; i++)
        {

        TextBox txtSkills = new TextBox();
        TextBox txtProficiency = new TextBox();

         Label lblSkills = new Label();
        Label lblProficiency = new Label();



         txtSkills.ID = "txtSkills" + i.ToString();
        txtSkills.Text = dt.Rows[i].ItemArray[1].ToString();
        txtProficiency.ID = "txtProficiency" + i.ToString();
        txtProficiency.Text = dt.Rows[i].ItemArray[2].ToString();


        lblSkills.ID = "lblSkills" + i.ToString();
        lblSkills.Text = "Skills:";
        lblProficiency.ID = "lblProficiency" + i.ToString(); 
        lblProficiency.Text = "Proficiency:";

           Panel3.Controls.Add(lblSkills);
           Panel3.Controls.Add(txtSkills);
           Panel3.Controls.Add(lblProficiency);
           Panel3.Controls.Add(txtProficiency);

以pdf格式保存的代码: -

    Response.ContentType = "application/pdf";
    Response.AddHeader("content-disposition", "attachment;filename=" somename ".pdf");
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);

    Panel3.RenderControl(hw);
    StringReader sr = new StringReader(sw.ToString());

    Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);

    Paragraph p1 = new Paragraph();
    p1.SpacingAfter = 15f;

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


    pdfDoc.Add(new Paragraph("Education"));
    htmlparser.Parse(sr);
    pdfDoc.Close();
    Response.Write(pdfDoc);
    Response.End();

0 个答案:

没有答案