Rotativa.AspNetCore
1.5.0
dotnet add package Rotativa.AspNetCore --version 1.5.0
NuGet\Install-Package Rotativa.AspNetCore -Version 1.5.0
<PackageReference Include="Rotativa.AspNetCore" Version="1.5.0" />
<PackageVersion Include="Rotativa.AspNetCore" Version="1.5.0" />
<PackageReference Include="Rotativa.AspNetCore" />
paket add Rotativa.AspNetCore --version 1.5.0
#r "nuget: Rotativa.AspNetCore, 1.5.0"
#:package Rotativa.AspNetCore@1.5.0
#addin nuget:?package=Rotativa.AspNetCore&version=1.5.0
#tool nuget:?package=Rotativa.AspNetCore&version=1.5.0
Create PDFs and images with .NET
Use Rotativa to transform a Razor view into a PDF or image. This package is compatible with .NET Core 3.1, .NET 5, .NET 6, .NET 7, .NET 8 and .NET 10.
Install with nuget.org:
https://www.nuget.org/packages/Rotativa.AspNetCore
Please give feedback!
Needs configuration
Basic configuration done in Program.cs (.NET 6 up to 10):
app.UseRotativa();
or, if using .NET Core 3.1 and .NET 5:
app.UseRotativa(env);
Make sure you have a folder with the wkhtmltopdf.exe file (and wkhtmltoimage.exe for images) accessible by the process running the web app. On Linux and macOS the files are named wkhtmltopdf and wkhtmltoimage, without the .exe extension: use the builds for your platform from https://wkhtmltopdf.org/downloads.html. By default it searches in a folder named "Rotativa" in the root of the web app. If you need to change that use the optional parameter to the Setup call RotativaConfiguration.Setup(env, "path/relative/to/root")
Usage
This package should work almost exactly as Rotativa https://github.com/webgio/Rotativa.
Instead of returning a View() in your .NET controller, use new ViewAsPdf() to return a PDF or use new ViewAsImage() to return an image:
public class InvoiceController : Controller
{
private readonly ILogger<InvoiceController> _logger;
public InvoiceController(ILogger<InvoiceController> logger)
{
_logger = logger;
}
public IActionResult Index()
{
// Returns the Index view as HTML.
return View();
}
public IActionResult Invoice()
{
// Returns the Invoice view as PDF.
return new ViewAsPdf();
}
public IActionResult InvoiceImage()
{
// Returns the InvoiceImage view as PDF.
return new ViewAsImage();
}
}
You can specify the View that should be transformed into a PDF or image:
return new ViewAsPdf("NameOfView");
Pass ViewData as an optional property:
ViewData["Message"] = "Thank you for downloading this PDF.";
return new ViewAsPdf(viewData: ViewData);
We support partial views as well:
return new ViewAsImage("MyPartialView", isPartialView: true);
By default Rotativa injects a base url in the head section of the HTML. This can be disabled:
return new ViewAsImage(setBaseUrl: false);
The settings can be combined as well:
ViewData["Message"] = "Thank you for downloading this PDF.";
return new ViewAsImage("MyPartialView", isPartialView: true, viewData: ViewData, setBaseUrl: false);
To change the way the PDF or image is generated, you can pass the settings as parameters:
return new ViewAsImage()
{
Format = ImageFormat.png,
Quality = 90
};
By default the PDF or image is shown to the user in the browser, like HTML. If you want to force the document to be downloaded use the Content-Disposition property:
return new ViewAsPdf()
{
ContentDisposition = ContentDisposition.Attachment,
FileName = "MyDocument.pdf"
};
Each property is documented in the object for easy reference.
Rotativa uses wkhtmltopdf/wkhtmltoimage behind the scenes. If you want to specify custom switches that are unsupported by Rotativa, you can pass them as well:
return new ViewAsPdf()
{
CustomSwitches = "--disable-smart-shrinking"
};
If you need to write the PDF to the server, you can call BuildFile and use the resulting byte array to save the file:
var pdfFile = new ViewAsPdf().BuildFile(this.ControllerContext);
File.WriteAllBytes("wwwroot/output.pdf", pdfFile);
This is how you save the PDF file to the server before displaying it in the browser:
public IActionResult Invoice()
{
// Generate the PDF.
var pdfFile = new ViewAsPdf();
// Save to the server.
File.WriteAllBytes("wwwroot/output.pdf", pdfFile.BuildFile(this.ControllerContext));
// Show in the browser.
return pdfFile;
}
Issues and Pull Request
Contribution is welcomed. If you would like to provide a PR please add some testing.
rotativa.io
rotativa.io is an API (SaaS) version of Rotativa, hosted on Azure. Works with just a HTTP call, no need to host the process on your server. You can register for free.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 is compatible. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETCoreApp 3.1
- No dependencies.
-
.NETStandard 2.0
- Microsoft.AspNetCore.Mvc (>= 2.3.13)
-
net10.0
- No dependencies.
-
net5.0
- No dependencies.
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Rotativa.AspNetCore:
| Package | Downloads |
|---|---|
|
WebSDK
WebSDK Mvc Projeler İçin Geliştirme Araçları |
|
|
Our.Umbraco.TemplateToPdf
This Package helps you to dynamically convert html templates to Pdfs! All in Umbraco context! |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on Rotativa.AspNetCore:
| Repository | Stars |
|---|---|
|
Harsha-Global/AspNetCore-Harsha
Asp.Net Core Ultimate Guide course | Web University by Harsha
|
| Version | Downloads | Last Updated |
|---|---|---|
| 1.5.0 | 180 | 10/8/2026 |
| 1.4.0 | 443,864 | 11/6/2024 |
| 1.3.2 | 404,330 | 11/12/2023 |
| 1.3.2-beta | 758 | 10/18/2023 |
| 1.2.0 | 777,711 | 9/19/2021 |
| 1.2.0-beta | 447,160 | 10/5/2019 |
| 1.1.1 | 541,564 | 11/17/2018 |
| 1.1.0 | 2,918 | 11/17/2018 |
| 1.0.6 | 87,903 | 2/10/2018 |
1.5.0
- Added .NET 10 support. The package targets .NET Standard 2.0, .NET Core 3.1, .NET 5, 6, 7, 8 and 10.
- .NET Standard 2.0 (used by .NET Framework apps): the Microsoft.AspNetCore.Mvc dependency moves from 2.2.0 to 2.3.13, which brings patched versions of Newtonsoft.Json, System.Text.Encodings.Web and System.Security.Cryptography.Xml. ASP.NET Core 2.3 is the version Microsoft supports on .NET Framework; it is based on 2.1, so apps that use ASP.NET Core 2.2 packages will be moved up to 2.3.13 and any 2.2-only APIs are not available.
- Linux and macOS: Rotativa looks for wkhtmltopdf and wkhtmltoimage without the .exe extension. Use the native builds for your platform from https://wkhtmltopdf.org/downloads.html.
- No changes to the public API.