如何将字符串转换为PDF格式并保存在文件夹中 [英] How to convert string into pdf and save in folder
本文介绍了如何将字符串转换为PDF格式并保存在文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码,但是输出错误输入字符串格式不正确请帮助
Here is my code but it is throwing error "input string was not in correct format" please help
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();
}
}
}
推荐答案
请访问以下链接:
http://www.roseindia.net/java/java-conversion/TextToPDF.shtml [ ^ ]
问候,
Bh @ gyesh
Hi,
Please visit following link :
http://www.roseindia.net/java/java-conversion/TextToPDF.shtml[^]
Regards,
Bh@gyesh
下一行:
The next line:
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:
msg += "<p style=\"font-family:verdana; font-size:13px; color:#161616;\">Artha Travels</p>";
这篇关于如何将字符串转换为PDF格式并保存在文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文