I am able to download and store the pdf document that is being generated but instead of downloading I want to open it in browser. I have something like this
MemoryStream os = new MemoryStream();
PdfWriter writer = new PdfWriter(os);
var pdfDocument = new PdfDocument(writer);
using (var document = new Document(pdfDocument))
{
//I am 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 is further being sent to controller and there it is being downloaded but I want to open in new browser. For me, "Content-disposition", "attachment;filename" is not working.
My return value is being passed on the controller further where I am storing in blob and continues to 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);
}