Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set .pdf name but prevent download with Rotativa

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!

like image 387
Ioana Stoian Avatar asked Sep 13 '25 17:09

Ioana Stoian


2 Answers

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");
like image 61
Bora Karaca Avatar answered Sep 16 '25 07:09

Bora Karaca


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!

like image 25
Ioana Stoian Avatar answered Sep 16 '25 06:09

Ioana Stoian