Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
344 views
in Technique[技术] by (71.8m points)

html - How to make a client receive a copy of a form they filled in, as a PDF in ASP.NET + C#

I'm creating a form in ASP.NET and want the customer to receive the PDF copy of the form when they have filled it in and submitted it; i.e. I need to create a PDF copy of the HTML form, with the customer information filled in.

I've tried different sources, but many that i have seen are just a set of tables; I haven't seen one that has a custom form with the information that a customer has just filled in.

How can I create a PDF from an existing form and a set of customer data?

Here is my code so far:

protected void btnExport_Click(object sender, EventArgs e)
    {
        string ubARSpecials = "";
        if (CheckBox_Specials.Checked)
        {
            ubARSpecials = "1";
        }
        else
        {
            ubARSpecials = "0";
        }

        string Query = "Insert into NewClient_Information(Name, Trading_As, ubARSpecials) values ('" + Txtbox_CompanyN.Text.Replace("'", "''") + "', '" + Txtbox_TrandingAs.Text.Replace("'", "''") + "', '" + ubARSpecials + "'); ";
        SqlCommand cmd = new SqlCommand(Query, conn);

        try
        {
            conn.Open();
            myReader = cmd.ExecuteReader();

            MessageBox.Show(this.Page, "Submitted Succesfully");

            Txtbox_TrandingAs.Text = "";
            Txtbox_CompanyN.Text = "";
            CheckBox_Specials.Checked = false;
        }


        catch (Exception ex)
        {
            MessageBox.Show(this.Page, ex.Message);
        }

        conn.Close();



        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=Panel.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        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();
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...