//add name space
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;
using iTextSharp.text.html.simpleparser;
using iTextSharp.text;
//String
StringBuilder strBuilder = new StringBuilder();
strBuilder.Append("<h1 title='Header'
align='Center'>Writing To Word File using windows form in c#</h1>
".ToString());
strBuilder.Append("<br>".ToString());
strBuilder.Append("<table border='1'
align='Center'>".ToString());
strBuilder.Append("<tr>".ToString());
strBuilder.Append("<td
style='width:30%;color:green'><b>Krishna Kumar
Chaturvedi</b></td>".ToString());
strBuilder.Append("<td
style='width:30%;color:red'>India</td>".ToString());
strBuilder.Append("<td style='width:30%;color:red'>Software
developer</td>".ToString());
strBuilder.Append("</tr>".ToString());
strBuilder.Append("</table>".ToString());
string strPath = textBox1.Text + "Test" + DateTime.Now.ToString("hhmmss") + ".pdf";
//Create PDF
using (FileStream stream = new FileStream(strPath,
FileMode.Create))
{
Document pdfDoc = new Document(PageSize.A2, 10f, 10f, 10f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc,
stream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
stream.Close();
}
No comments:
Post a Comment