1
Reply

Download pdf throws error in c#

Sivakumar

Sivakumar

Apr 26 2016 11:44 AM
341
Hi This is my code :
 
 
StringBuilder sb = new StringBuilder();
sb.Append("<header class='clearfix'>");
sb.Append("<div id='company' class='clearfix'>");

sb.Append("<td>" + "<img src=\"data:image/png;base64," + tempimage + "\" />" + "</td>");
sb.Append("<div>(602) 519-0450</div>");
sb.Append("<div><a href='mailto:[email protected]'>[email protected]</a></div>");
sb.Append("</div>");
sb.Append("<div id='project'>");
sb.Append("<div><span>PROJECT</span> Website development</div>");
sb.Append("<div><span>CLIENT</span> John Doe</div>");
sb.Append("<div><span>ADDRESS</span> 796 Silver Harbour, TX 79273, US</div>");
sb.Append("<div><span>EMAIL</span> <a href='mailto:[email protected]'>[email protected]</a></div>");
sb.Append("<div><span>DATE</span> April 13, 2016</div>");
sb.Append("<div><span>DUE DATE</span> May 13, 2016</div>");
sb.Append("</div>");
sb.Append("</header>");
sb.Append("<main>");
sb.Append("<table>");
sb.Append("<thead>");
sb.Append("<tr>");
sb.Append("<th class='service'>SERVICE</th>");
sb.Append("<th class='desc'>DESCRIPTION</th>");
sb.Append("<th>PRICE</th>");
sb.Append("<th>QTY</th>");
sb.Append("<th>TOTAL</th>");
sb.Append("</tr>");
sb.Append("</thead>");
sb.Append("<tbody>");
sb.Append("<tr>");
sb.Append("<td class='service'>Design</td>");
sb.Append("<td class='desc'>Creating a recognizable design solution based on the company's existing visual identity</td>");
sb.Append("<td class='unit'>$400.00</td>");
sb.Append("<td class='qty'>2</td>");
sb.Append("<td class='total'>$800.00</td>");
sb.Append("</tr>");
sb.Append("<tr>");
sb.Append("<td colspan='4'>SUBTOTAL</td>");
sb.Append("<td class='total'>$800.00</td>");
sb.Append("</tr>");
sb.Append("<tr>");
sb.Append("<td colspan='4'>TAX 25%</td>");
sb.Append("<td class='total'>$200.00</td>");
sb.Append("</tr>");
sb.Append("<tr>");
sb.Append("<td colspan='4' class='grand total'>GRAND TOTAL</td>");
sb.Append("<td class='grand total'>$1,000.00</td>");
sb.Append("</tr>");
sb.Append("</tbody>");
sb.Append("</table>");
sb.Append("<div id='notices'>");
sb.Append("<div>NOTICE:</div>");
sb.Append("<div class='notice'>A finance charge of 1.5% will be made on unpaid balances after 30 days.</div>");
sb.Append("</div>");
sb.Append("</main>");
sb.Append("<footer>");
sb.Append("Invoice was created on a computer and is valid without the signature and seal.");
sb.Append("</footer>");


StringReader sr = new StringReader(sb.ToString());
document.Open();
htmlparser.Parse(sr);
document.NewPage();

}
document.Close();

}


bytes = ms.ToArray();


}

Response.Clear();
//string pdfName = "template";
Response.AddHeader("Content-Disposition", "attachment; filename=" + orderID + "_" + "template" + ".pdf");
Response.ContentType = "application/pdf";
Response.Buffer = true;
Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
Response.BinaryWrite(bytes);
Response.End();
Response.Close(); 
 
 throwing error like :
 
 
 
I added base64 string to the img src in string builder. if i remove image it will works fine.
 Please give me proper solution.
Thanks.
 

Answers (1)