This code snippet using the Controller Context Response to view the PDF file in another window without downloading it or showing in the same window. Below is the snippet:
- public ActionResult ReportTest()
- {
- var pdfResult = new PartialViewAsPdf("_pdfTemplate")
- {
-
- FileName = Constants.PDF_REPORT_NAME + DateTime.Now.ToShortDateString() + Constants.PDF_EXT,
-
- CustomSwitches = "ADD SWITCHES HERE FOR HEADER FOOTER"
- };
-
- Response.Clear();
- Response.ClearContent();
- Response.ClearHeaders();
-
- var resultSet = pdfResult.BuildPdf(ControllerContext);
- Response.Buffer = true;
-
- Response.ContentType = "application/pdf";
- Response.AddHeader("Accept-Ranges", "bytes");
-
- Response.BinaryWrite(resultSet);
-
- Response.End();
- Response.Flush();
-
- return null;
- }
Hope this helps in any application of yours where you are generating PDF and showing in another window using Rotativa.