I'm using C# to create a multiple textbox form that will be completed by the user and exported to PDF. I'm not sure about how to create it. Should I create a database? Use StreamWriter? A different approach? I've never created anything like this before and I've searched endlessly.
I've used StreamWriter before, but I could only apply it one textbox. I would also like the user to be able to save their inputs and open them (MenuStrip).
Any advice? Sincerely, thanks in advance!
Kayla GPosted Aug 14, 2015, 7:31 AM
Looking at the code, it looks like I'll need iTextSharp pdfwriter. I'll get that and try it. After that, I'll mark your answer. Thanks for your help!
Sumit JoshiPosted Aug 14, 2015, 7:14 AM
Kayla GPosted Aug 14, 2015, 7:04 AM
Sumit JoshiPosted Aug 14, 2015, 5:50 AM
Document pdfDoc = new Document();
try
{
PdfWriter.GetInstance(pdfDoc, System.Web.HttpContext.Current.Response.OutputStream);
pdfDoc.Open();
//Set Font Properties for PDF File
Font fnt = FontFactory.GetFont("Times New Roman", 14);
PdfPTable PdfTable = new PdfPTable(1);
PdfPCell PdfPCell = null;
//Retrieve content from design side
string chk;
chk = "address";
string adr1 = txtadr1.Text;
PdfPCell = new PdfPCell(new Phrase(new Chunk(chk + adr1)));
PdfTable.AddCell(PdfPCell);
string adr2 = txtadr2.Text;
PdfPCell addrchk = new PdfPCell(new Phrase(new Chunk(adr2)));
PdfTable.AddCell(addrchk);
string adr3 = txtadr3.Text;
PdfPCell addrchk1 = new PdfPCell(new Phrase(new Chunk(adr3)));
PdfTable.AddCell(addrchk1);
string cty = txtcty.Text;
PdfPCell cty1 = new PdfPCell(new Phrase(new Chunk(cty)));
PdfTable.AddCell(cty1);
string stat = txtstat.Text;
PdfPCell stat1 = new PdfPCell(new Phrase(new Chunk(stat)));
PdfTable.AddCell(stat1);
string code = txtcode.Text;
PdfPCell code1 = new PdfPCell(new Phrase(new Chunk(code)));
PdfTable.AddCell(code1);
string cntry = txtcntry.Text;
PdfPCell cntry1 = new PdfPCell(new Phrase(new Chunk(cntry)));
PdfTable.AddCell(cntry1);
string mob = txtmbl.Text;
PdfPCell mob1 = new PdfPCell(new Phrase(new Chunk(mob)));
PdfTable.AddCell(mob1);
pdfDoc.Add(PdfTable);
pdfDoc.Close();
Response.ContentType = "application/pdf";
System.Web.HttpContext.Current.Response.Write(pdfDoc);
Response.Flush();
Response.End();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
Contact Information