Rotativa HTML to PDF on ASP.NET MVC: how to create PDF as a landscape?

Stefano Guimarães Falce picture Stefano Guimarães Falce · Apr 5, 2017 · Viewed 11.6k times · Source

I'm using Rotativa resources to create PDF files from my HTML page on an MVC ASP.NET project. Here is my code:

Controller:

public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View();
    }

    public ActionResult ExportPDF()
    {
        return new ActionAsPdf("Index")
        {
            FileName = Server.MapPath("~/Content/Relato.pdf")
        };
    }
}

View

<a href="@Url.Action("ExportPDF","Home")" class="hidden-print" >EXPORT PDF</a>

The PDF documents being created are in portrait layout. How could I set them into landscape layout?

Cheers!

Answer

Stefano Guimar&#227;es Falce picture Stefano Guimarães Falce · Apr 5, 2017

Just solved the issue. Here is the updated code (See PageOrientation and PageSize lines):

public ActionResult ExportPDF()
        {
            return new ActionAsPdf("Index")
            {
                FileName = Server.MapPath("~/Content/Relato.pdf"),
                PageOrientation = Rotativa.Options.Orientation.Landscape,
                PageSize = Rotativa.Options.Size.A4
            };
        }

Cheers!