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.
I installed the "Rotativa.AspNetCore" nuget in my Blazor server project in .NET 8
Added
RotativaConfiguration.Setup(app.Environment.WebRootPath); app.UseRotativa();in Program.csCreated a "Views" folder with a PDF.cshtml view
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?

I got it working by myself. It is totally possible to use rotativa.exe and Rotativa.AspNetCore nuget to generate PDFs in Blazor using the "ViewAsPdf" method. My initial setup was good and I added following two controller methods:
which calls following that creates the pdf using rotativa:
}
and calling it from .razor component via:
I have also tried creating an API controller and send it a post request with whole PDF model, but the PDF never displayed in the browser, but got returned to the calling object in razor code.