Theoistic.RazorPDF
1.2.0
See the version list below for details.
dotnet add package Theoistic.RazorPDF --version 1.2.0
NuGet\Install-Package Theoistic.RazorPDF -Version 1.2.0
<PackageReference Include="Theoistic.RazorPDF" Version="1.2.0" />
paket add Theoistic.RazorPDF --version 1.2.0
#r "nuget: Theoistic.RazorPDF, 1.2.0"
// Install Theoistic.RazorPDF as a Cake Addin #addin nuget:?package=Theoistic.RazorPDF&version=1.2.0 // Install Theoistic.RazorPDF as a Cake Tool #tool nuget:?package=Theoistic.RazorPDF&version=1.2.0
RazorPDF
RazorPDF is a powerful library for .NET that provides capabilities to build PDF documents using Razor views. With RazorPDF, you can create complex PDF documents, render HTML content, and apply styles, all with the familiar Razor syntax and .NET environment. It's perfect for generating invoices, reports, forms, and more!
Features
- Generate PDFs using familiar Razor syntax and views.
- Inject CSS for styling your PDFs.
- Comprehensive PDF settings like compression, size, orientation, and more.
- Asynchronous methods for building PDFs.
Installation
You can add RazorPDF to your project via the NuGet package manager. Use the following command in your Package Manager Console:
Install-Package Theoistic.RazorPDF
Configuration
To use RazorPDF in your project, you need to configure the services and application builder typically in your Startup.cs
.
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPDF();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseRazorPDF();
}
Quick Start
Here's a quick demonstration of how you can generate a PDF from a Razor view.
First, create your Razor view (e.g., PDFViews/NicePDF.cshtml). This view will contain the HTML structure and content that will be rendered in your PDF.
@model NicePDFModel
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="~/PDFStyle.css">
</head>
<body>
<h1>My Nice PDF</h1>
<table>
@foreach (var item in Model.Items)
{
<tr>
<td>@item.Name</td>
<td>@item.Value</td>
</tr>
}
</table>
</body>
</html>
In your controller or service, use PDFBuilder to generate the PDF:
public async Task CreatePDF()
{
var pdf = await new PDFBuilder()
.Settings(x =>
{
x.UseCompression = true;
})
.InjectCSS("wwwroot/PDFStyle.css")
.RazorView("PDFViews/NicePDF", new NicePDFModel {
Items = new List<NicePDFModel.Item> {
new NicePDFModel.Item { Name = "Something", Value = "10.42" },
new NicePDFModel.Item { Name = "Something else", Value = "50.42" },
new NicePDFModel.Item { Name = "Something more", Value = "21.42" },
}
})
.BuildAsync();
System.IO.File.WriteAllBytes("test.pdf", pdf);
}
This will create a PDF document from your Razor view with the data you provided and save it as test.pdf. Contributing
Contributions to the RazorPDF library are welcome! If you're interested in improving RazorPDF
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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 was computed. 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. |
-
net7.0
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.