In ASP.NET Core MVC, the most common way to print/export reports as PDF is using a PDF library like:
Rotativa.AspNetCore (Easy for Razor Views)
DinkToPdf (Production-grade)
QuestPDF (Best for complex reports)
iText7 (Advanced enterprise)
For MVC Razor report printing, I recommend DinkToPdf.
Step 1: Install Package
dotnet add package DinkToPdf
Download wkhtmltopdf native library from wkhtmltopdf official site
Put DLL in:
wwwroot/lib/
Step 2: Register Service
Program.cs
using DinkToPdf;
using DinkToPdf.Contracts;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSingleton(typeof(IConverter),
new SynchronizedConverter(new PdfTools()));
builder.Services.AddControllersWithViews();
var app = builder.Build();
app.Run();
Step 3: Create PDF Service
PdfService.cs
using DinkToPdf;
using DinkToPdf.Contracts;
public class PdfService
{
private readonly IConverter _converter;
public PdfService(IConverter converter)
{
_converter = converter;
}
public byte[] GeneratePdf(string html)
{
var doc = new HtmlToPdfDocument()
{
GlobalSettings = {
PaperSize = PaperKind.A4,
Orientation = Orientation.Portrait
},
Objects = {
new ObjectSettings()
{
HtmlContent = html
}
}
};
return _converter.Convert(doc);
}
}
Step 4: Register Service
Program.cs
builder.Services.AddScoped<PdfService>();
Step 5: Controller Action
ReportController.cs
public class ReportController : Controller
{
private readonly PdfService _pdfService;
public ReportController(PdfService pdfService)
{
_pdfService = pdfService;
}
public IActionResult Print()
{
var html = @"
<h1>Employee Report</h1>
<table border='1' width='100%'>
<tr>
<th>ID</th>
<th>Name</th>
</tr>
<tr>
<td>1</td>
<td>John</td>
</tr>
</table>";
var pdf = _pdfService.GeneratePdf(html);
return File(pdf, "application/pdf", "Report.pdf");
}
}
Step 6: Print Button
View
<a href="/Report/Print" target="_blank"
class="btn btn-primary">
Print PDF
</a>
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
In ASP.NET Core MVC, the most common way to print/export reports as PDF is using a PDF library like:
For MVC Razor report printing, I recommend DinkToPdf.
Step 1: Install Package
Download wkhtmltopdf native library from
wkhtmltopdf official site
Put DLL in:
Step 2: Register Service
Program.cs
Step 3: Create PDF Service
PdfService.cs
Step 4: Register Service
Program.cs
Step 5: Controller Action
ReportController.cs
Step 6: Print Button
View
If Using Razor View as Report
Render View → Convert HTML → Generate PDF
Example:
(If using Rotativa)
Official docs:
Rotativa.AspNetCore GitHub
Best Choice
For your production MVC Core app:
There are many method to do this.. I am telling you one of it
First install rotativa and include assembly
then use it as shown in code
I hope this will helps you