Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 983
Sachin Kumar Avatar asked Jan 07 '13 13:01

Sachin Kumar


1 Answers

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

like image 146
derekadk Avatar answered Sep 21 '22 02:09

derekadk