Adliance.AspNetCore.Buddy.Pdf 8.0.0.3

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
dotnet add package Adliance.AspNetCore.Buddy.Pdf --version 8.0.0.3
NuGet\Install-Package Adliance.AspNetCore.Buddy.Pdf -Version 8.0.0.3
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="Adliance.AspNetCore.Buddy.Pdf" Version="8.0.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Adliance.AspNetCore.Buddy.Pdf --version 8.0.0.3
#r "nuget: Adliance.AspNetCore.Buddy.Pdf, 8.0.0.3"
#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 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 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 (1)

Showing the top 1 NuGet packages that depend on Adliance.AspNetCore.Buddy.Pdf:

Package Downloads
Adliance.AspNetCore.Buddy.Template.Razor The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

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.3 153 4/11/2024
8.0.0.2 613 3/15/2024
8.0.0.1 92 3/15/2024
6.0.16 6,320 11/16/2022
6.0.14 297 11/16/2022
6.0.11 1,778 7/25/2022
6.0.10 867 7/25/2022
6.0.9 412 7/23/2022
6.0.8 580 7/10/2022
6.0.7 414 7/10/2022
6.0.5 3,630 6/20/2022
6.0.4 527 6/20/2022
6.0.3 706 6/8/2022
6.0.2 507 6/8/2022
6.0.1 609 6/8/2022
5.4.13 740 5/30/2022
5.4.10 3,127 10/28/2021
5.4.7 2,087 9/7/2021
5.4.5 436 8/19/2021
5.4.4 304 8/19/2021
5.4.2 1,019 6/9/2021
5.4.1 1,404 6/5/2021
5.3.2 1,065 4/2/2021
5.3.1 368 4/2/2021
5.2.2 1,279 3/3/2021
5.2.1 807 1/14/2021
5.1.2 1,036 12/1/2020
5.1.1 397 12/1/2020
5.0.7 931 11/19/2020
5.0.6 534 11/19/2020
5.0.3 561 11/19/2020
5.0.2 484 11/19/2020
4.0.10 796 9/21/2020
4.0.9 760 9/20/2020
4.0.8 491 9/20/2020
4.0.7 498 9/20/2020
4.0.6 502 9/15/2020
4.0.5 1,878 9/13/2020
4.0.3 680 9/13/2020
4.0.2 621 9/13/2020
4.0.1 765 9/13/2020