Search code examples
asp.net-mvcrotativa

Rotativa Download with SaveAs dialog


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.


Solution

  • 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. :)