Adliance.AspNetCore.Buddy.Pdf
8.0.0.3
Prefix Reserved
See the version list below for details.
dotnet add package Adliance.AspNetCore.Buddy.Pdf --version 8.0.0.3
NuGet\Install-Package Adliance.AspNetCore.Buddy.Pdf -Version 8.0.0.3
<PackageReference Include="Adliance.AspNetCore.Buddy.Pdf" Version="8.0.0.3" />
paket add Adliance.AspNetCore.Buddy.Pdf --version 8.0.0.3
#r "nuget: Adliance.AspNetCore.Buddy.Pdf, 8.0.0.3"
// Install Adliance.AspNetCore.Buddy.Pdf as a Cake Addin #addin nuget:?package=Adliance.AspNetCore.Buddy.Pdf&version=8.0.0.3 // Install Adliance.AspNetCore.Buddy.Pdf as a Cake Tool #tool nuget:?package=Adliance.AspNetCore.Buddy.Pdf&version=8.0.0.3
Adliance.AspNetCore.Buddy.Pdf
This PDF library creates a PDF from HTML with header and footer if provided. The Pdf library provides two versions of PDF generation.
- Version 1 (
Adliance.AspNetCore.Buddy.Pdf.V1
) uses wkhtmltopdf - Version 2 (
Adliance.AspNetCore.Buddy.Pdf.V2
) uses pdf-lib
Setup library in an ASP.NET project
The IBuddyServiceCollection
of the Adliance.AspNetCore.Buddy.Abstractions
package offers the AddBuddy
method, which provides several extensions to add the PDF services.
The library has two versions of the PDF service in following namespaces:
using Adliance.AspNetCore.Buddy.Pdf.V1;
using Adliance.AspNetCore.Buddy.Pdf.V2;
The methods are the same in every namespace, so be aware of using the correct using
statements when adding the PDF service with the AddPdf(configuration)
method.
public void ConfigureServices(IServiceCollection services)
{
//...
services.AddBuddy()
.AddPdf(Configuration.GetSection("Pdf"))
//...
}
Configuration (appsettings.json)
Add a section in the configuration of your project and point to the used PDF service endpoint.
{
"Pdf": {
"ServerUrl": "https://url-to-pdf.service"
}
}
Health check
The library also offers an extension to the IHealthChecksBuilder
to add a health check to the used PDF service.
services.AddHealthChecks()
.AddPdfCheck();
Usage of library
Generate a PDF
This code sample shows the usage of the PDF generator. Just call the HtmlToPdf
method with the HTML string and the PDF options.
IPdfer _pdfer = new AdliancePdfer(new DefaultPdferConfiguration());
byte[] bytes = await _pdfer.HtmlToPdf("This is <b>my</b> <u>HTML</u> code.", new PdfOptions());
PDF Options
Version 2
Name | Type | Description |
---|---|---|
HeaderHtml | string |
The HTML for the PDF header as string. |
HeaderHeight | int |
The height of the header in pixel (px). If a HeaderHtml is provided, the height must be set. |
FooterHtml | string |
The HTML for the PDF footer as string. |
FooterHeight | int |
The height of the footer in pixel (px). If a FooterHtml is provided, the height must be set. |
Useful information
Page numbers
To have page numbers, e.g in the footer of the PDF, there are two CSS classes. If placed on a span element, the content of the element is substituted with the appropriate value.
current-page
: Specifies the current page number.total-pages
: The total number of pages, which will be generated.
A HTML snippet could look like this:
<span class="current-page"></span> / <span class="total-pages"></span>
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. |
-
net8.0
- Adliance.AspNetCore.Buddy.Abstractions (>= 8.0.0.5)
- System.Text.Json (>= 8.0.3)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Adliance.AspNetCore.Buddy.Pdf:
Package | Downloads |
---|---|
Adliance.AspNetCore.Buddy.Template.Razor
Library of utility methods and common functionality that are useful for most Adliance projects. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
8.0.0.6 | 1,923 | 9/4/2024 |
8.0.0.5 | 1,361 | 7/17/2024 |
8.0.0.4 | 186 | 5/28/2024 |
8.0.0.3 | 1,547 | 4/11/2024 |
8.0.0.2 | 2,037 | 3/15/2024 |
8.0.0.1 | 119 | 3/15/2024 |
6.0.16 | 7,252 | 11/16/2022 |
6.0.14 | 320 | 11/16/2022 |
6.0.11 | 1,852 | 7/25/2022 |
6.0.10 | 899 | 7/25/2022 |
6.0.9 | 424 | 7/23/2022 |
6.0.8 | 592 | 7/10/2022 |
6.0.7 | 444 | 7/10/2022 |
6.0.5 | 3,793 | 6/20/2022 |
6.0.4 | 558 | 6/20/2022 |
6.0.3 | 743 | 6/8/2022 |
6.0.2 | 550 | 6/8/2022 |
6.0.1 | 641 | 6/8/2022 |
5.4.13 | 782 | 5/30/2022 |
5.4.10 | 3,152 | 10/28/2021 |
5.4.7 | 2,134 | 9/7/2021 |
5.4.5 | 462 | 8/19/2021 |
5.4.4 | 331 | 8/19/2021 |
5.4.2 | 1,055 | 6/9/2021 |
5.4.1 | 1,457 | 6/5/2021 |
5.3.2 | 1,093 | 4/2/2021 |
5.3.1 | 403 | 4/2/2021 |
5.2.2 | 1,325 | 3/3/2021 |
5.2.1 | 842 | 1/14/2021 |
5.1.2 | 1,070 | 12/1/2020 |
5.1.1 | 425 | 12/1/2020 |
5.0.7 | 977 | 11/19/2020 |
5.0.6 | 571 | 11/19/2020 |
5.0.3 | 597 | 11/19/2020 |
5.0.2 | 518 | 11/19/2020 |
4.0.10 | 827 | 9/21/2020 |
4.0.9 | 788 | 9/20/2020 |
4.0.8 | 522 | 9/20/2020 |
4.0.7 | 534 | 9/20/2020 |
4.0.6 | 536 | 9/15/2020 |
4.0.5 | 1,944 | 9/13/2020 |
4.0.3 | 713 | 9/13/2020 |
4.0.2 | 657 | 9/13/2020 |
4.0.1 | 809 | 9/13/2020 |