Rotativa Download with SaveAs dialog

Sachin Kumar picture Sachin Kumar · Jan 7, 2013 · Viewed 9.5k times · Source

I am using Rotativa tool to display pdf. It works fine with the following code:

public ActionResult PreviewDocument()
{

     var htmlContent = Session["html"].ToString();
     var model = new PdfInfo { Content = htmlContent, Name = "PDF Doc" };
     return new ViewAsPdf(model);
}

I wanted to know the way to download the pdf via browser's "save as" dialog on clicking on a button and not to display in some iframe. "new ViewAsPdf(model)" just returns the pdf data.

Thanks in advance.

Answer

derekadk picture derekadk · Jan 6, 2015

You can add additional attributes to the Rotativa call like this:

return new PartialViewAsPdf("PreviewDocument", pdfModel)
                   {
                       PageSize = Size.A4,
                       FileName = "PDF Doc.pdf"
                   };

And it'll create the file for you. :)