Nudes.Pedreizor
0.2.0
See the version list below for details.
dotnet add package Nudes.Pedreizor --version 0.2.0
NuGet\Install-Package Nudes.Pedreizor -Version 0.2.0
<PackageReference Include="Nudes.Pedreizor" Version="0.2.0" />
paket add Nudes.Pedreizor --version 0.2.0
#r "nuget: Nudes.Pedreizor, 0.2.0"
// Install Nudes.Pedreizor as a Cake Addin #addin nuget:?package=Nudes.Pedreizor&version=0.2.0 // Install Nudes.Pedreizor as a Cake Tool #tool nuget:?package=Nudes.Pedreizor&version=0.2.0
Pedreizor
A friendly converter of razor templates for pdf in aspnetcore environment
This library is made up of a Razor to html converter and an html to pdf converter using the DinkToPdf library as a dependency, which in turn uses the webkit pdf renderer
Get Started
Pedreizor can be installed using the Nuget package manager or the dotnet CLI
Install-Package Pedreizor
Razor renderer
The part responsible for transforming razor files into html strings is an instance that implements the IRazorRenderer interface and can be used by dependency injection as follows
The Startup.cs
services.AddMvc().AddRazorRenderer();
Any class that requires razor-html conversion
...
public PocController(IRazorRenderer razorRenderer)
{
this.razorRenderer = razorRenderer;
}
...
private async Task<string> RenderingWithoutModel()
{
string htmlString = await razorRenderer.Render(new Uri("/Template/Index.cshtml", UriKind.Relative));
return htmlString;
}
private async Task<string> RenderingWithModel()
{
string htmlString = await razorRenderer.Render<ExampleModel>(new Uri("/Template/Index.cshtml", UriKind.Relative), new ExampleModel
{
Text = "Razor converter"
});
return htmlString;
}
Pedreizor
The part responsible for converting the html strings into pdf is the responsibility of Pedreizor, and can be configured and used as follows
Startup.cs
services.AddMvc().AddRazorRenderer();
services.AddPedreizor();
or
services.AddMvc().AddRazorRenderer();
services.AddPedreizor(new PedreizorOptions
{
PageCounterVisible = true,
PageCounterPosition = PageNumberPosition.FooterRight,
Paper = PaperType.A4
});
or else
services.AddMvc().AddRazorRenderer();
services.AddPedreizor(()=> new PedreizorOptions
{
PageCounterVisible = true,
PageCounterPosition = PageNumberPosition.FooterRight,
Paper = PaperType.A4
});
Any class that requires razor-pdf or html-pdf conversion
...
public PocController(IRazorRenderer razorRenderer, IPedreizor pedreizor)
{
this.pedreizor = pedreizor;
this.razorRenderer = razorRenderer;
}
...
private async Task<Stream> ConvertingPureHtmlText()
{
string htmlContent = "<h1>Hello World</h1>";
Stream stream = await pedreizor.Pdfy(htmlContent);
return stream;
}
private async Task<Stream> ConvertingPureHtmlTextOfARazorFileUsingRazorRenderer()
{
string htmlString = await razorRenderer.Render(new Uri("/Template/Index.cshtml", UriKind.Relative));
Stream stream = await pedreizor.Pdfy(htmlString);
return stream;
}
private async Task<Stream> ConvertingPureHtmlTextOfARazorFileUsingPedreizor()
{
Stream stream = await pedreizor.Pdfy(new Uri("/Template/Index.cshtml", UriKind.Relative));
return stream;
}
private async Task<Stream> ConvertingRazorWithModelUsingPedreizor()
{
Stream stream = await pedreizor.Pdfy<ExampleModel>(new Uri("/Template/Index.cshtml", UriKind.Relative), new ExampleModel
{
Text = "Pedreizor converter"
});
return stream;
}
private async Task ConvertingRazorWithoutModelUsingPedreizorOnExistentStream(Stream stream)
{
await pedreizor.PdfyTo(new Uri("/Template/Index.cshtml", UriKind.Relative), stream);
}
private async Task ConvertingRazorWithModelUsingPedreizorOnExistentStream(Stream stream)
{
await pedreizor.PdfyTo<ExampleModel>(new Uri("/Template/Index.cshtml", UriKind.Relative), stream ,new ExampleModel
{
Text = "Pedreizor converter"
});
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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. |
.NET Core | netcoreapp2.2 is compatible. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
-
.NETCoreApp 2.2
- DinkToPdf (>= 1.0.8)
- Microsoft.AspNetCore.Mvc.Razor (>= 2.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.