c# - Saving iTextSharp pdf into byte and download with save dialog -


i'm trying create pdf using itextsharp , convert byte , download pdf file save dialog. have used memorystream convert pdf byte , used httpresponse page method download pdf file don't seem working. don't not have error , nothing happen after clicking button.(using chrome, firefox) me out , check part did did wrongly. thanks!

protected void btnpdf_click(object sender, eventargs e) { byte[] pdfbytes; using (var ms = new memorystream())c {     var doc1 = new document();     pdfwriter writer = pdfwriter.getinstance(doc1, ms);     doc1.open();      pdfptable table = new pdfptable(1);      table.totalwidth = 585f;     table.lockedwidth = true;      itextsharp.text.pdf.pdfpcell imgcell1 = new itextsharp.text.pdf.pdfpcell();      var logo = itextsharp.text.image.getinstance(server.mappath("~/image/logo.jpg"));     doc1.add(logo);      var titlefont = fontfactory.getfont("arial", 15, font.bold);     doc1.add(new paragraph("official report. member report id : " + ddlcase.selectedvalue, titlefont));      var normalfont = fontfactory.getfont(fontfactory.helvetica, 14, font.bold);     var phrase = new phrase();      sqlconnection con = new sqlconnection("data source = localhost; initial catalog = project; integrated security = sspi");      sqlcommand cm = new sqlcommand("select lro.fullname, lro.contact, mr.typeofcrime, mr.location,mr.crdatetime, mr.citizenreport, pr.policeid,  pr.prdatetime, pr.policereport, aor.officialreport,  mr.image1, mr.image2, mr.image3, mr.image4, mr.image5,  pr.image1, pr.image2, pr.image3, pr.image4, pr.image5 memberreport mr, policereport pr, loginregisterothers lro, adminofficialreport aor mr.memberreportid = '" + ddlcase.selectedvalue + "' , mr.memberreportid=pr.memberreportid , pr.policereportid=aor.policereportid", con);     con.open();     sqldatareader dr;      dr = cm.executereader();      if (dr.read())     {          phrase.add(new chunk("full name :", normalfont));         phrase.add(dr[0].tostring());          phrase.add(chunk.newline);         phrase.add(chunk.newline);         phrase.add(chunk.newline);         phrase.add(chunk.newline);          phrase.add(new chunk("contact :", normalfont));         phrase.add(dr[1].tostring());          phrase.add(chunk.newline);         phrase.add(chunk.newline);         phrase.add(chunk.newline);         phrase.add(chunk.newline);          phrase.add(new chunk("type of crime :", normalfont));         phrase.add(dr[2].tostring());          phrase.add(chunk.newline);         phrase.add(chunk.newline);         phrase.add(chunk.newline);         phrase.add(chunk.newline);          phrase.add(new chunk("location :", normalfont));         phrase.add(dr[3].tostring());          phrase.add(chunk.newline);         phrase.add(chunk.newline);         phrase.add(chunk.newline);         phrase.add(chunk.newline);          phrase.add(new chunk("citizen report date time :", normalfont));         phrase.add(dr[4].tostring());          phrase.add(chunk.newline);         phrase.add(chunk.newline);         phrase.add(chunk.newline);         phrase.add(chunk.newline);          phrase.add(new chunk("citizen report :", normalfont));         phrase.add(dr[5].tostring());          phrase.add(chunk.newline);         phrase.add(chunk.newline);         phrase.add(chunk.newline);         phrase.add(chunk.newline);          phrase.add(new chunk("citizen images :", normalfont));          phrase.add(new chunk("1.", normalfont));         byte[] bytes1 = (byte[])dr[10];         itextsharp.text.image image1 = itextsharp.text.image.getinstance(bytes1);         image1.scaletofit(1150f, 1150f);         chunk imagechunk1 = new chunk(image1, 0, 0);         phrase.add(imagechunk1);          phrase.add(new chunk("2.", normalfont));         byte[] bytes5 = (byte[])dr[11];         itextsharp.text.image image5 = itextsharp.text.image.getinstance(bytes5);         image5.scaletofit(1150f, 1150f);         chunk imagechunk5 = new chunk(image5, 0, 0);         phrase.add(imagechunk5);          phrase.add(new chunk("3.", normalfont));         byte[] bytes6 = (byte[])dr[12];         itextsharp.text.image image6 = itextsharp.text.image.getinstance(bytes6);         image6.scaletofit(1150f, 1150f);         chunk imagechunk6 = new chunk(image6, 0, 0);         phrase.add(imagechunk6);          phrase.add(new chunk("4.", normalfont));         byte[] bytes7 = (byte[])dr[13];         itextsharp.text.image image7 = itextsharp.text.image.getinstance(bytes7);         image7.scaletofit(1150f, 1150f);         chunk imagechunk7 = new chunk(image7, 0, 0);         phrase.add(imagechunk7);          phrase.add(new chunk("5.", normalfont));         byte[] bytes8 = (byte[])dr[14];         itextsharp.text.image image8 = itextsharp.text.image.getinstance(bytes8);         image8.scaletofit(1150f, 1150f);         chunk imagechunk8 = new chunk(image8, 0, 0);         phrase.add(imagechunk8);          table.addcell(phrase);     }     dr.close();     doc1.add(table);     doc1.newpage();     doc1.add(table2);     doc1.close();      pdfbytes = ms.toarray(); }  response.clear(); response.contenttype = "application/pdf"; response.appendheader("content-disposition", string.format("attachment; filename={0}", "report.pdf")); response.outputstream.write(pdfbytes, 0, pdfbytes.length);   } 

i test using ie error:

jscript anonymous function [microsoftajax.js] line 6 script

sorry guy there no error in code code don't work ajax control updatepanel. thank viewing, helping.

use this

 string filename = string.format(guid.newguid()+".pdf");  htmltopdf(server.mappath(@"~\temp\") + filename);  response.appendheader("content-disposition", "attachment; filename=" + filename);  response.contenttype = "application/pdf";  response.transmitfile(filepath);  response.end(); 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -