First include these references like
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html.simpleparser;
protected void CreatePdf_Click(object sender,
EventArgs e)
{
var document = new
Document(PageSize.A4, 50, 50, 25, 25);
// Create a new PdfWrite object,
writing the output to a MemoryStream
var output = new MemoryStream();
var writer =
PdfWriter.GetInstance(document, output);
// Open the Document for writing
document.Open();
// Read in the contents of the
Receipt.htm HTML template file
string contents =
File.ReadAllText(Server.MapPath("~/PdfTemplate/Receipt.htm"));
// Replace the placeholders with the
user-specified text
var itemsTable = @"<table><tr><th
style=""font-weight: bold"">Product #</th><th style=""font-weight:
bold"">Qty</th><th style=""font-weight: bold"">Price</th><th
style=""font-weight: bold"">Total Amount</th></tr>";
SqlConnection con = new
SqlConnection("server=192.168.1.50;database=Qwizo_Dev;user id=QwizoDev;password=Qwizo@123");
con.Open();
string query = "select *from TestUser";
string query1 = "select *from
TestProduct";
using (SqlCommand cmd = new
SqlCommand(query, con))
{
using (SqlDataReader dr =
cmd.ExecuteReader())
{
if (dr.Read())
{
contents =
contents.Replace("[Name]", dr[1].ToString() + " " + dr[2].ToString());
Join the conversation! Your thoughts help the community grow.