c# - instead of downloading Open pdf in browser(using itext) mvc -


i able download , store pdf document being generated instead of downloading want open in browser. have

memorystream os = new memorystream(); pdfwriter writer = new pdfwriter(os); var pdfdocument = new pdfdocument(writer);  using (var document = new document(pdfdocument)) {   //i adding different sections here } var response = new httpresponsemessage {     statuscode = httpstatuscode.ok,     content = new bytearraycontent(os.toarray()) };  response.content.headers.add("content-type", "application/pdf"); response.headers.add("content-disposition", "attachment;filename=" + "testpdf.pdf"); return response; 

the response further being sent controller , there being downloaded want open in new browser. me, "content-disposition", "attachment;filename" not working.

my return value being passed on controller further storing in blob , continues download.

public async task<iactionresult> generatedocument(int id)     {         var result = await _applicationservice.generatedocument(id);         var blobresult = await _applicationservice.savedocument(id, result.responseobject);          iactionresult onsuccess() =>             new redirectresult(blobresult.responseobject.uri, true);          return handleresult(onsuccess, blobresult.status);     } 

you want use inline content disposition let browser know display it

//...code removed brevity var buffer = os.toarray(); var contentlength = buffer.length; var statuscode = httpstatuscode.ok; var response = request.createresponse(statuscode); response.content = new bytearraycontent(buffer); response.content.headers.contenttype = new mediatypeheadervalue("application/pdf"); response.content.headers.contentlength = contentlength; contentdispositionheadervalue contentdisposition = null; if (contentdispositionheadervalue.tryparse("inline; filename=" + "testpdf.pdf", out contentdisposition)) {     response.content.headers.contentdisposition = contentdisposition; } return response; 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -