Nudes.Pedreizor 0.2.0

There is a newer version of this package available.
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                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Nudes.Pedreizor" Version="0.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Nudes.Pedreizor --version 0.2.0                
#r "nuget: Nudes.Pedreizor, 0.2.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.5.6 1,526 9/2/2021
0.5.5 1,167 9/2/2021
0.5.4 870 8/17/2021
0.5.3 1,082 8/17/2021
0.5.2 919 8/17/2021
0.5.1 691 8/16/2021 0.5.1 is deprecated because it has critical bugs.
0.5.0 594 8/16/2021 0.5.0 is deprecated because it has critical bugs.
0.3.0 1,098 9/24/2019
0.2.0 600 7/2/2019