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.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
Model
public class Customer
{
public string CustomerId { get; set; }
public string ContactName { get; set; }
public string Country { get; set; }
}
Namespaces
using Rotativa.AspNetCore;
Controller
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
};
}
}
View
@model List<EF_Core_MVC.Models.Customer>
@addTagHelper*, Microsoft.AspNetCore.Mvc.TagHelpers
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<form method="post" asp-action="Export" asp-controller="Home">
<input type="submit" value="Submit" />
</form>
<hr />
<table cellpadding="0" cellspacing="0">
<tr>
<th>Id</th>
<th>Name</th>
<th>Country</th>
</tr>
@foreach (var customer in Model)
{
<tr>
<td>@customer.CustomerId</td>
<td>@customer.ContactName</td>
<td>@customer.Country</td>
</tr>
}
</table>
</body>
</html>
Screenshot