Create PDF in Asp.Net Core on Windows and Linux

date Nov 28, 2017

Creating PDF files in Asp.Net Core is now really easy with the Rotativa.io Asp.Net Core client. This means that now you can use Rotativa code on Linux! Yu won’t have any problems since all your code will do is call a HTTP API service.

Installation is easy. You need to add the package to you project.

For .Net Framework you would need to add the RotativaHQ.AspNetCore package to you project, either by using the Package Manager UI or on the Package Manager console by typing:

PM> Install-Package RotativaHQ

For .Net Core you can use the .Net CLI:

> dotnet add package RotativaHQ.AspNetCore

Configuration is done by code in the Startup.cs file:

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    // ....
    RotativaHqConfiguration.SetRotativaHqApiKey("<YOUR KEY>");
    RotativaHqConfiguration.SetRotativaHqUrl("<YOUR ENDPOINT");
}

You should replace placeholders with the values you will find in your account preferences page. You can register for one at the Rotativa.io Singup page (free account is available).

Creating PDF docs from your views will exactly the same as in Rotativa and Rotativa.io .Net:

public ActionResult MyAction()
{
    // ... 
    return new ViewAsPdf();
}