c# - PDFsharp not giving pdf file in response -
i working on export functionality using pdfsharp in .net mvc not getting error in code not getting pdf file in response.
i have tried doing manually writing specific path of : system.io.file.writeallbytes(path1, bytes);
, it's working perfectly, not getting pdf in response of
response.binarywrite(bytes); response.outputstream.write(bytes, 0, bytes.length);
anyone have faced type of issue or community please here code :
public bool exportpdf(string htmlcontenttbl) { response.clearcontent(); response.buffer = true; response.addheader("content-disposition", "attachment;filename=myfile.pdf"); response.contenttype = "application/pdf"; response.charset = ""; stringwriter sw = new stringwriter(); htmltextwriter htw = new htmltextwriter(sw); pdfdocument document = pdfgenerator.generatepdf(htmlcontenttbl.tostring(), pdfsharp.pagesize.a4, 30); var config = new pdfgenerateconfig(); config.pageorientation = pageorientation.landscape; config.pagesize = pagesize.a4; config.marginbottom = 30; config.margintop = 30; byte[] bytes = null; using (memorystream stream = new memorystream()) { document.save(stream, true); bytes = stream.toarray(); } var path1 = server.mappath("~/images/" + datetime.now.timeofday.ticks + "result.pdf"); //system.io.file.writeallbytes(path1, bytes); //response.binarywrite(bytes); //response.outputstream.write(bytes, 0, bytes.length); response.flush(); response.end(); return true; }
thank you,
Comments
Post a Comment