Click here to Skip to main content
15,917,608 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is my code but it is throwing error "input string was not in correct format" please help
C#
protected void btnGeneratePDF_Click(object sender, EventArgs e)
{
   try
   {
     string sess = Session["LogId"].ToString();
            sqlCon = new SqlConnection(conString);
            sqlCom = new SqlCommand("usp_Invoice_Master", sqlCon);
            sqlCom.CommandType = CommandType.StoredProcedure;
            sqlCom.Parameters.AddWithValue("@Type", "PDF");
            
            if (sqlCon.State == ConnectionState.Broken || sqlCon.State == ConnectionState.Closed)
                sqlCon.Open();
            SqlDataAdapter da = new SqlDataAdapter(sqlCom);
            sqlCon.Close();
            DataTable dt = new DataTable();
            da.Fill(dt);
            string msg = string.Empty;
            if (dt.Rows.Count > 0)
       {

                 msg += "<p style="font-family:verdana; font-size:13px; color:#161616;">Artha Travels</p>";
                    msg += "<p>Invoice</p>";
                
                    msg += "<table width="600px" cellspacing="0" cellpadding="5" border="1"> ";


                    msg += "<tr>";
                    msg += "<td>This is testing </td>";
                    msg += "<td>" + dt.Rows[0]["Invoice No"].ToString() + "</td>";
                    msg += "<td>" + dt.Rows[0]["Client Name"].ToString() + "</td>";
                    msg += "<td>" + dt.Rows[0]["Trip Id"].ToString() + "</td>";
                    msg += "<td>" + dt.Rows[0]["Trip Type"].ToString() + "</td>";
                    msg += "<td>" + dt.Rows[0]["Trip Details"].ToString() + "</td>";
                    msg += "<td>" + dt.Rows[0]["Car Details"].ToString() + "</td>";
                    msg += "<td>" + dt.Rows[0]["Total Ammount"].ToString() + "</td>";
                    msg += "<td>" + dt.Rows[0]["Balance Ammount"].ToString() + "</td>";
                    msg += "</tr>";


                    msg += "</table>";
                    msg += "<p></p>";



              
       }
var doc1 = new iTextSharp.text.Document();

            string path = Server.MapPath("~/Invoices/Pdf");

            string pdffilename = "Invoice " + dt.Rows[0]["Invoice No"] + "(" + DateTime.Now.ToString("dd-MM-yyyy") + ")" + ".pdf";

            PdfWriter.GetInstance(doc1, new FileStream(path + "/" + pdffilename, FileMode.Create));

            doc1.Open();

       iTextSharp.text.html.simpleparser.StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();

       iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(doc1);

       hw.Parse(new StringReader(msg));

       doc1.Close();



   }
   catch (Exception ex)
   {
       MessageBox.Show(ex.Message.ToString());
   }
   finally
   {
       if (sqlCon.State == ConnectionState.Open)
       {
           sqlCon.Close();
       }
   }
}
Posted
Updated 20-May-14 18:56pm
v2
Comments
DamithSL 21-May-14 1:00am    
can you compile this code!
msg += "<table width="600px" cellspacing="0" cellpadding="5" border="1"> ";
i think it should be change as
msg += "<table width='600px' cellspacing='0' cellpadding='5' border='1'> ";
Hadees 21-May-14 2:19am    
thanks for your reply, i tried above solution but still exception is coming

Hi,

Please visit following link :

http://www.roseindia.net/java/java-conversion/TextToPDF.shtml[^]

Regards,
Bh@gyesh
 
Share this answer
 
The next line:
C#
msg += "<p style="font-family:verdana; font-size:13px; color:#161616;">Artha Travels</p>";

generates the error, so you should change it by using \" in plase of " like in the next example:
C#
msg += "<p style=\"font-family:verdana; font-size:13px; color:#161616;\">Artha Travels</p>";
 
Share this answer
 
v2
Comments
Hadees 21-May-14 2:22am    
Thanks for your valuable reply, i tried above solution but its not working and still exception is throwing."Input string was not in correct format"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900