0

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();
    }
i alarmed alien
  • 9,412
  • 3
  • 27
  • 40
  • Whenever someone looking to answer questions about iText on Stack Overflow sees the class `HTMLWorker` in a code sample, that person will refer to [Converting HTML to PDF with iText](https://stackoverflow.com/questions/47895935) to explain that `HTMLWorker` is obsolete. Forms aren't supported in `HTMLWorker` (and they never will). Only iText 7 + pdfHTML supports forms as explained in the [FAQ: Can I convert an HTML form to a PDF?](https://developers.itextpdf.com/content/itext-7-converting-html-pdf-pdfhtml/chapter-7-frequently-asked-questions-about-pdfhtml/can-i-convert-html-form-pdf). – Bruno Lowagie Aug 01 '18 at 12:56
  • grammar/understandability – i alarmed alien Aug 01 '18 at 13:00
  • Thank i will try it on my project. – Ntobe Pearl Khoza Aug 01 '18 at 14:17

0 Answers0