I am using Itextsharp to generate PDF while exporting i have a image which is coming from server which is in byte format . It shows Illegal characters in path. please help me.
.aspx
<asp:Image ID="img_dealer" runat="server" Width="150px" Height="150px" />
.cs
if (dt.Rows[0]["Photo"].ToString().Trim() != null || dt.Rows[0]["Photo"].ToString().Trim() != "")
{
Session["Photo"] = (byte[])dt.Rows[0]["Photo"];
string encrypt_id = Utilities.encrypt(Utilities.convt("3"), ConfigurationManager.AppSettings["AadharEncKey"]);
img_dealer.ImageUrl = "Image.aspx?id=" + encrypt_id + "";
Session["ImageUrl"] = "Image.aspx?id=" + encrypt_id + "";
}
private byte[] GetImage(string RegNO)
{
if (con.State == ConnectionState.Closed)
con.Open();
string sTSQL = "select Photo from FL_Form_A1 where Reg_No='" + RegNO + "'";
SqlCommand objCmd = new SqlCommand(sTSQL, con);
objCmd.CommandType = CommandType.Text;
object result = objCmd.ExecuteScalar();
con.Close();
return (byte[])result;
}
protected void export_click(object sender, EventArgs e)
{
string strid = Utilities.Decrypt(Request.QueryString["lbid1122"].ToString().Trim().Replace(" ", "+"), ConfigurationManager.AppSettings["AadharEncKey"]);
string appPath = HttpContext.Current.Request.ApplicationPath;
govlogo.ImageUrl = Server.MapPath(".") + "\\Image\\kar_logo4.jpg";
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(GetImage(strid));
string path = Server.MapPath(appPath + "eSign/eSignfiles/" + strid + ".pdf");
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=" + strid + ".pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
this.Page.RenderControl(hw);
dynamic output = new FileStream(path, FileMode.Create);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 88f, 88f, 10f, 10f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, output);
pdfDoc.Open();
//pdfDoc.Add(img);
htmlparser.Parse(sr);
pdfDoc.Close();
}