Adliance.AspNetCore.Buddy.Pdf 8.0.0.4

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Adliance.AspNetCore.Buddy.Pdf --version 8.0.0.4                
NuGet\Install-Package Adliance.AspNetCore.Buddy.Pdf -Version 8.0.0.4                
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.4" />                
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.4                
#r "nuget: Adliance.AspNetCore.Buddy.Pdf, 8.0.0.4"                
#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.4

// Install Adliance.AspNetCore.Buddy.Pdf as a Cake Tool
#tool nuget:?package=Adliance.AspNetCore.Buddy.Pdf&version=8.0.0.4                

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

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 2,044 9/4/2024
8.0.0.5 1,363 7/17/2024
8.0.0.4 188 5/28/2024
8.0.0.3 1,608 4/11/2024
8.0.0.2 2,039 3/15/2024
8.0.0.1 121 3/15/2024
6.0.16 7,278 11/16/2022
6.0.14 322 11/16/2022
6.0.11 1,854 7/25/2022
6.0.10 901 7/25/2022
6.0.9 426 7/23/2022
6.0.8 594 7/10/2022
6.0.7 446 7/10/2022
6.0.5 3,795 6/20/2022
6.0.4 560 6/20/2022
6.0.3 745 6/8/2022
6.0.2 552 6/8/2022
6.0.1 643 6/8/2022
5.4.13 784 5/30/2022
5.4.10 3,154 10/28/2021
5.4.7 2,136 9/7/2021
5.4.5 464 8/19/2021
5.4.4 333 8/19/2021
5.4.2 1,057 6/9/2021
5.4.1 1,459 6/5/2021
5.3.2 1,095 4/2/2021
5.3.1 405 4/2/2021
5.2.2 1,327 3/3/2021
5.2.1 844 1/14/2021
5.1.2 1,072 12/1/2020
5.1.1 427 12/1/2020
5.0.7 981 11/19/2020
5.0.6 573 11/19/2020
5.0.3 599 11/19/2020
5.0.2 520 11/19/2020
4.0.10 829 9/21/2020
4.0.9 790 9/20/2020
4.0.8 524 9/20/2020
4.0.7 536 9/20/2020
4.0.6 538 9/15/2020
4.0.5 1,946 9/13/2020
4.0.3 715 9/13/2020
4.0.2 659 9/13/2020
4.0.1 811 9/13/2020