I need to set .pdf name before displaying it. I tried to set it like this
return new ViewAsPdf(GetViewName(), "", reportVM)
{
PageSize = Size.Letter, FileName = GetViewName() + "-" + DateTime.Now.ToShortDateString() + ".pdf"
}; ,
but in this way the .pdf will be automatically downloaded. Is it possible to set the .pdf name and not downloading it?
Thanks!
var pdfResult = new Rotativa.PartialViewAsPdf("YourPartialView", model) {
SaveOnServerPath = path, // Save your place
PageWidth = 200,
PageHeight = 350,
};
// This section allows you to save without downloading
pdfResult.BuildPdf(this.ControllerContext);
return RedirectToAction("Index", "Home");
After long research, the answer is no. The only thing that I could do is to set file name using response header and remove property FileName, so the code is now:
Response.AppendHeader("Content-Disposition", "inline; filename=" +GetViewName() + "_" + DateTime.Now.ToShortDateString() + ".pdf");
return new ViewAsPdf(GetViewName(), "", reportVM) { PageSize = Size.Letter };
Maybe there is a better solution, but that's the best I could get after all the reading. Hope it will help others too!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With