Set PDF page size in Rotativa plugin in ASP.Net Core

on Jul 20, 2022 10:54 PM

I am developing a system in core and rotativa pdf, in this I need to print sales tickets.

How can I establish in a pdf rotativa that the size of the page is of the ticket type?

I use printing from a pdf rotativa press on ticket printers, those used in supermarkets to print the sales ticket.

In printing I find, among other sizes, such as letter or legal but there is no way to tell that the size is a ticket type that has a width but not a height.

Do you know how to indicate the type of ticket in rotativa pdf?

Download FREE API for Word, Excel and PDF in ASP.Net: Download
on Jul 29, 2022 12:16 AM

Hi jmontano,

You need to set options to the rendering engine. You have to set PageWidth and PageHeight and Margins in millimeters.

Check the example.


For this example I have used of Northwind database that you can download using the link given below.

Download Northwind Database


public class Customer
    public string CustomerId { get; set; }
    public string ContactName { get; set; }
    public string Country { get; set; }


using Rotativa.AspNetCore;


public class HomeController : Controller
    private DBCtx Context { get; }
    public HomeController(DBCtx _context)
        this.Context = _context;

    public IActionResult Index()
        return View(this.Context.Customers.ToList());

    public IActionResult Export()
        return new ViewAsPdf("Index", this.Context.Customers.ToList())
            FileName = "Customers.pdf",
            PageMargins = { Left = 0, Right = 0 }, // In millimeters.
            PageWidth = 80, // In millimeters.
            PageHeight = 200


@model List<EF_Core_MVC.Models.Customer>
@addTagHelper*, Microsoft.AspNetCore.Mvc.TagHelpers

    Layout = null;

<!DOCTYPE html>

    <meta name="viewport" content="width=device-width" />
    <form method="post" asp-action="Export" asp-controller="Home">
        <input type="submit" value="Submit" />
    <hr />
    <table cellpadding="0" cellspacing="0">
        @foreach (var customer in Model)