Flaminco.RazorInk 1.46.0

dotnet add package Flaminco.RazorInk --version 1.46.0                
NuGet\Install-Package Flaminco.RazorInk -Version 1.46.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="Flaminco.RazorInk" Version="1.46.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Flaminco.RazorInk --version 1.46.0                
#r "nuget: Flaminco.RazorInk, 1.46.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 Flaminco.RazorInk as a Cake Addin
#addin nuget:?package=Flaminco.RazorInk&version=1.46.0

// Install Flaminco.RazorInk as a Cake Tool
#tool nuget:?package=Flaminco.RazorInk&version=1.46.0                

Flaminco.RazorInk

Flaminco.RazorInk is designed to simplify the process of generating PDF based on Razor

Installation

dotnet add package Flaminco.RazorInk

Getting Started

Installation

Step 1: Add Migration to Your Services

To get started with Flaminco.RazorInk, you need to configure the Migration services in your ASP.NET Core application. You can do this by adding the following line:

Using Direct Configuration


builder.Services.AddRazorInk();
Step 2: Inject IRazorInkPdfGenerator
[ApiController]
[Route("api/pdf")]
public class PdfController : ControllerBase
{
    private readonly IPdfRazorInk _pdfGenerator;

    public PdfController(IPdfRazorInk pdfGenerator)
    {
        _pdfGenerator = pdfGenerator;
    }

    [HttpPost("generate")]
    public async Task<IActionResult> GeneratePdf([FromBody] Invoice invoiceModel)
    {
        PagePdfOptions pdfOptions = new PagePdfOptions
        {
            Format = "A4",
            DisplayHeaderFooter = true,
            HeaderTemplate = "<div style='font-size:12px; text-align:center; width:100%;'>Invoice Header</div>",
            FooterTemplate = "<div style='font-size:12px; text-align:center; width:100%;'>Page <span class='pageNumber'></span> of <span class='totalPages'></span></div>",
            PrintBackground = true,
        };

        byte[] pdfBytes = await _pdfGenerator.RenderAsync<InvoiceComponent>(new Dictionary<string, object?>
        {
            { "Invoice", invoiceModel }
        }, pdfOptions);

        return File(pdfBytes, "application/pdf", "document.pdf");
    }
}


@code {
    [Parameter] public Invoice Invoice { get; set; } // Note that the property name must matchs the key name in the Dictionary
}

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <title>Invoice @Invoice.Number</title>

    <style>
        /* Your Style */
	</style>
</head>

<body>
    <div class="invoice-box page-break">
    <table cellpadding="0" cellspacing="0">
        <tr class="top">
            <td colspan="2">
                <table>
                    <tr>
                        <td>
                            Invoice #: @Invoice.Number<br/>
                            Created: @Invoice.IssueDate.ToString("MMMM dd, yyyy")<br/>
                            Due: @Invoice.DueDate.ToString("MMMM dd, yyyy")
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
		
    </table>
</div>
</body>
</html>

Placeholders:

  • <span class='pageNumber'></span> this placeholder is for writing the current page number
  • <span class='totalPages'></span> this placeholder is for writing the total page numbers.

Containerize

Replace FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base with FROM mcr.microsoft.com/playwright/dotnet:v1.46.0-jammy AS base

Where v1.46.0 matches the current playwright

Where you can also check the last docker image for dotnet from here

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.

License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET 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. 
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
1.46.0 103 9/8/2024
0.0.1 104 9/6/2024