Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotativa PDF export - unable to display inline and having a filename at the same time

I found Rotativa as an easy way to export to PDF (works almost perfectly except CSS3 doesn't seem to be supported, maybe in a future version) ... but I wonder how to handle the FileName option.

When I

return new Rotativa.ViewAsPdf("myViewName", "~/Views/Shared/_PDFLayout.cshtml", myModel)
{
    FileName = "myCorrectlyNamed.pdf",
    PageSize = ... // plus some more options
};

then I'll get myCorrectlyNamed.pdf for download. When I omit the FileName option, the PDF is displayed in the browser, but when I save it from there, it has just the default filename document.pdf.

How to generate and display the pdf in the browser and have a filename other than document.pdf when it's saved from there?

like image 771
outofmind Avatar asked Mar 14 '23 03:03

outofmind


1 Answers

You can add Content-Disposition header to the Response. Using this header, you'll be able to tell the browser to display the file inline and also specify the name that should be used when user tries to Save the file.

Response.AppendHeader("Content-Disposition", new System.Net.Mime.ContentDisposition { Inline = true, FileName = "myCorrectlyNamed.pdf" }.ToString());
return new Rotativa.ViewAsPdf("myViewName", "~/Views/Shared/_PDFLayout.cshtml", myModel)
{
    PageSize = ... // plus some more options
};
like image 157
sachin Avatar answered May 13 '23 11:05

sachin