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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…