Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

How to use wkhtmltopdf Rotativa ViewAsPdf in Blazor Server

$
0
0

I would like to use Rotativa.AspNetCore.ViewAsPdf("~/Views/MyView/PDF.cshtml", model)in Blazor Server the same way I do in regular ASP.NET CORE MVC apps.

  1. I installed the "Rotativa.AspNetCore" nuget in my Blazor server project in .NET 8

  2. Added RotativaConfiguration.Setup(app.Environment.WebRootPath); app.UseRotativa(); in Program.cs

  3. Created a "Views" folder with a PDF.cshtml view

  4. Created a Controller I am calling via httpClient from my razor component to generate the PDF

[HttpPost("exportPDF")]public ActionResult ExportPDF(PDFModel model){    return new Rotativa.AspNetCore.ViewAsPdf("~/Views/MyView/PDF.cshtml", model)    {        FileName = "MyFile" + DateTime.Now.ToString("yyyyMMddHHmmss") +".pdf",        PageSize = Rotativa.AspNetCore.Options.Size.A4,        PageOrientation = Rotativa.AspNetCore.Options.Orientation.Portrait,        PageMargins = { Left = 15, Right = 15, Top = 15 },        CustomSwitches = "--footer-center \"MyDocument +"\" --footer-right \"Page: [page]/[toPage]\" --footer-font-size \"6\""    };}

And I am getting an "Object reference not set to an instance of an object." exception from the "Rotativa.AspNetCore" source.

Has anyone got this working in Blazor?


Viewing all articles
Browse latest Browse all 4839

Trending Articles