asp.net - Getting error to generate pdf -
protected void txt_btn_click(object sender, eventargs e) { response.contenttype = "application/pdf"; response.addheader("content-disposition", "attachment;filename=testresult.pdf"); response.cache.setcacheability(httpcacheability.nocache); stringbuilder htmltext = new stringbuilder(); htmltext.append("<table style='color:red;' border='1'><tr><th>createing pdf</th><tr><td> abcdef</td></tr></table>"); stringreader stringreader = new stringreader(htmltext.tostring()); document doc = new document(pagesize.a4); list<itextsharp.text.ielement> elements = itextsharp.text.html.simpleparser.htmlworker.parsetolist(stringreader, null); doc.open(); foreach (object item in elements) { doc.add((ielement)item); } doc.close(); // response output pdfwriter.getinstance(doc, response.outputstream); doc.open(); //doc.close(); response.write("pdf created"); }
}
i try create pdf file.but pdf created 0kb.mean when open it's shw error may pdf damaged
i'm assuming using itextsharp library.
private void generatepdf() { try { string pdfpath = "~/pdf/file_1.pdf"; stringbuilder sb = new stringbuilder(); sb.append("name : chamara" + environment.newline); sb.append("address : sri lanaka" + environment.newline); sb.append("institute : sliit" + environment.newline); document doc = new document(); pdfwriter.getinstance(doc, new filestream(server.mappath(pdfpath), filemode.create)); doc.open(); doc.add(new paragraph(sb.tostring())); doc.close(); } catch (exception ex) { throw ex; } }
Comments
Post a Comment