简体   繁体   中英

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

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!

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM