Flaminco.RazorInk
0.0.1
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Flaminco.RazorInk --version 0.0.1
NuGet\Install-Package Flaminco.RazorInk -Version 0.0.1
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="0.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Flaminco.RazorInk --version 0.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Flaminco.RazorInk, 0.0.1"
#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=0.0.1 // Install Flaminco.RazorInk as a Cake Tool #tool nuget:?package=Flaminco.RazorInk&version=0.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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 IRazorInkPdfGenerator _pdfGenerator;
public PdfController(IRazorInkPdfGenerator 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.RenderHtmlToPdfAsync<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.
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 | Versions 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.
-
net8.0
- Microsoft.AspNetCore.Components.Web (>= 8.0.8)
- Microsoft.Playwright (>= 1.46.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.