QuestPDF 2021.12.0-alpha1

.NET Core 2.0 .NET Standard 2.0 .NET Framework 4.6.2
This is a prerelease version of QuestPDF.
There is a newer version of this package available.
See the version list below for details.
dotnet add package QuestPDF --version 2021.12.0-alpha1
NuGet\Install-Package QuestPDF -Version 2021.12.0-alpha1
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="QuestPDF" Version="2021.12.0-alpha1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add QuestPDF --version 2021.12.0-alpha1
#r "nuget: QuestPDF, 2021.12.0-alpha1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install QuestPDF as a Cake Addin
#addin nuget:?package=QuestPDF&version=2021.12.0-alpha1&prerelease

// Install QuestPDF as a Cake Tool
#tool nuget:?package=QuestPDF&version=2021.12.0-alpha1&prerelease

QuestPDF Overview

QuestPDF is an open-source, modern and battle-tested library that can help you with generating PDF documents by offering friendly, discoverable and predictable C# fluent API.

Features

Rely on solid fundamentals - This library is created specifically for designing and arranging document layouts, with full paging support. Alternative solutions, such as HTML-based converters, are not designed for this purpose and therefore are often unpredictable and do not produce desired results.

Work with organized self-explanatory code - The entire process of implementing PDF document, takes place in your code. Free yourself from slow visual designers and strange technological limitations. Follow simple yet highly effective approaches to create maintainable, high-quality code.

Compose simple components into complex documents - Do you remember the feeling when your code just works? When your ideas are becoming real without any effort? Working with simple, easy to understand, self-explanatory and highly composable layout elements is the key here!

Create and reuse components - Feel no fear of complex documents! Create custom, reusable components and divide the document's layout into easy to maintain pieces. Inject data to customize content and use slots to enhance composability. Decide how complex approaches your solution needs and follow the best path.

Prototype with ease - We understand that document generation is often tricky and require multiple iterations. The library offers additional prototyping tools such as random text generator or image placeholder element. By following best practices, you can develop a document without having data.

Enjoy fast PDF generation - QuestPDF is created upon SkiaSharp, a well-known graphical library, and converts your data into PDF documents. It offers a highly optimized layouting engine capable of generating over 1000 PDF files per minute per core. The entire process is thread-safe.

Learning resources

Release notes and roadmap - everything that is planned for future library iterations, description of new features and information about potential breaking changes.

Getting started tutorial - a short and easy to follow tutorial showing how to design an invoice document under 200 lines of code.

API Reference - a detailed description of behavior of all available components and how to use them with C# Fluent API.

Patterns and practices - everything that may help you designing great reports and reusable code that is easy to maintain.

Example invoice

Do you believe that creating a complete invoice document can take less than 200 lines of code? We have prepared for you a step-by-step instruction that shows every detail of this implementation and describes the best patterns and practices.

For tutorial, documentation and API reference, please visit the QuestPDF documentation.

invoice

Here you can find an example code showing how easy is to write and understand the fluent API.

General document structure with header, content and footer:

public void Compose(IDocumentContainer container)
{
    container
        .Page(page =>
        {
            page.Margin(50);
            
            page.Header().Element(ComposeHeader);
            page.Content().Element(ComposeContent);
            
            page.Footer().AlignCenter().Text(x =>
            {
                x.CurrentPageNumber();
                x.Span(" / ");
                x.TotalPages();
            });
        });
}

The header area consists of basic invoice information along with a logo placeholder.

void ComposeHeader(IContainer container)
{
    var titleTextStyle = TextStyle.Default.Size(20).SemiBold().Color(Colors.Blue.Medium);
    
    container.Row(row =>
    {
        {
            stack.Item().Text($"Invoice #{Model.InvoiceNumber}", titleStyle);

            stack.Item().Text(text =>
            {
                text.Span("Issue date: ", TextStyle.Default.SemiBold());
                text.Span($"{Model.IssueDate:d}");
            });

            stack.Item().Text(text =>
            {
                text.Span("Due date: ", TextStyle.Default.SemiBold());
                text.Span($"{Model.DueDate:d}");
            });
        });
        
        row.ConstantColumn(100).Height(50).Placeholder();
    });
}

Implementation of the content area that contains seller and customer details, then listing of all bought products, then a comments section.

void ComposeContent(IContainer container)
{
    container.PaddingVertical(40).Stack(column => 
    {
        column.Spacing(20);
        
        column.Item().Row(row =>
        {
            row.RelativeColumn().Component(new AddressComponent("From", Model.SellerAddress));
            row.ConstantColumn(50);
            row.RelativeColumn().Component(new AddressComponent("For", Model.CustomerAddress));
        });

        column.Item().Element(ComposeTable);

        var totalPrice = Model.Items.Sum(x => x.Price * x.Quantity);
        
        column
            .Item()
            .PaddingRight(5)
            .AlignRight()
            .Text($"Grand total: {totalPrice}$", TextStyle.Default.SemiBold());

        if (!string.IsNullOrWhiteSpace(Model.Comments))
            column.Item().PaddingTop(25).Element(ComposeComments);
    });
}

The table and comments codes are extracted into separate methods to increase clarity:

void ComposeTable(IContainer container)
{
    var headerStyle = TextStyle.Default.SemiBold();
    
    container.Decoration(decoration =>
    {
        // header
        decoration.Header().BorderBottom(1).Padding(5).Row(row => 
        {
            row.ConstantColumn(25).Text("#", headerStyle);
            row.RelativeColumn(3).Text("Product", headerStyle);
            row.RelativeColumn().AlignRight().Text("Unit price", headerStyle);
            row.RelativeColumn().AlignRight().Text("Quantity", headerStyle);
            row.RelativeColumn().AlignRight().Text("Total", headerStyle);
        });

        // content
        decoration
            .Content()
            .Stack(column =>
            {
                foreach (var item in Model.Items)
                {
                    column
                    .Item()
                    .ShowEntire()
                    .BorderBottom(1)
                    .BorderColor(Colors.Grey.Lighten2)
                    .Padding(5)
                    .Row(row => 
                    {
                        row.ConstantColumn(25).Text(Model.Items.IndexOf(item) + 1);
                        row.RelativeColumn(3).Text(item.Name);
                        row.RelativeColumn().AlignRight().Text($"{item.Price}$");
                        row.RelativeColumn().AlignRight().Text(item.Quantity);
                        row.RelativeColumn().AlignRight().Text($"{item.Price * item.Quantity}$");
                    });
                }
            });
    });
}
void ComposeComments(IContainer container)
{
    container.ShowEntire().Background(Colors.Grey.Lighten3).Padding(10).Stack(message => 
    {
        message.Spacing(5);
        message.Item().Text("Comments", TextStyle.Default.Size(14).SemiBold());
        message.Item().Text(Model.Comments);
    });
}

The address details section is implemented using components. This way the code can be easily reused for both seller and customer:

public class AddressComponent : IComponent
{
    private string Title { get; }
    private Address Address { get; }

    public AddressComponent(string title, Address address)
    {
        Title = title;
        Address = address;
    }
    
    public void Compose(IContainer container)
    {
        container.ShowEntire().Stack(column =>
        {
            column.Spacing(5);

            column
                .Item()
                .BorderBottom(1)
                .PaddingBottom(5)
                .Text(Title, TextStyle.Default.SemiBold());
            
            column.Item().Text(Address.CompanyName);
            column.Item().Text(Address.Street);
            column.Item().Text($"{Address.City}, {Address.State}");
            column.Item().Text(Address.Email);
            column.Item().Text(Address.Phone);
        });
    }
}
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (9)

Showing the top 5 NuGet packages that depend on QuestPDF:

Package Downloads
AgentHub.Service.Financial.Domain.Shared

Package Description

A2v10.Pdf.Report

A2v10 Platform PDF report

Verify.QuestPDF The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Extends Verify (https://github.com/VerifyTests/Verify) to allow verification via QuestPDF.

ReportBuilder

Package Description

HTMLToQPDF

HTMLToQPDF is an extension for QuestPDF that allows to generate PDF from HTML

GitHub repositories (4)

Showing the top 4 popular GitHub repositories that depend on QuestPDF:

Repository Stars
beto-rodriguez/LiveCharts2
Simple, flexible, interactive & powerful charts, maps and gauges for .Net, LiveCharts2 can now practically run everywhere Maui, Uno Platform, Blazor-wasm, WPF, WinForms, Xamarin, Avalonia, WinUI, UWP.
axzxs2001/Asp.NetCoreExperiment
原来所有项目都移动到**OleVersion**目录下进行保留。新的案例装以.net 5.0为主,一部分对以前案例进行升级,一部分将以前的工作经验总结出来,以供大家参考!
QuestPDF/QuestPDF-ExampleInvoice
BoletoNet/BoletoNetCore
Versão do BoletoNet para .NET Core
Version Downloads Last updated
2022.11.0 15,300 11/5/2022
2022.11.0-alpha1 58 11/1/2022
2022.11.0-alpha0 43 10/28/2022
2022.9.1 22,289 10/15/2022
2022.9.0 26,411 9/18/2022
2022.9.0-alpha1 62 9/16/2022
2022.8.2 35,306 8/21/2022
2022.8.1 2,986 8/19/2022
2022.8.0 9,429 8/15/2022
2022.6.3 26,938 7/18/2022
2022.6.2 41,369 6/22/2022
2022.6.1 11,527 6/12/2022
2022.6.0 28,415 6/12/2022
2022.6.0-prerelease 1,085 5/30/2022
2022.5.0 120,497 5/9/2022
2022.4.1 26,656 4/8/2022
2022.4.0 19,645 4/4/2022
2022.4.0-alpha1 103 3/27/2022
2022.4.0-alpha0 71 3/27/2022
2022.3.1 59,578 3/15/2022
2022.3.0 1,222 3/14/2022
2022.2.7 1,113 3/12/2022
2022.2.6 4,902 3/8/2022
2022.2.5 10,564 2/18/2022
2022.2.4 194 2/18/2022
2022.2.3 8,583 2/7/2022
2022.2.2 957 2/1/2022
2022.2.1 764 1/30/2022
2022.2.0 796 1/29/2022
2022.2.0-beta1 99 1/24/2022
2022.1.0 12,106 1/10/2022
2022.1.0-beta5 608 1/7/2022
2022.1.0-beta4 100 1/6/2022
2022.1.0-beta3 97 1/5/2022
2022.1.0-beta2 92 1/5/2022
2022.1.0-beta1 97 1/3/2022
2022.1.0-beta0 95 12/30/2021
2022.1.0-alpha0 118 12/30/2021
2021.12.0 16,354 12/6/2021
2021.12.0-alpha1 920 11/29/2021
2021.12.0-alpha0 156 11/18/2021
2021.11.4 13,188 11/14/2021
2021.11.3 3,121 11/7/2021
2021.11.0-beta3 150 11/3/2021
2021.11.0-beta2 200 10/28/2021
2021.11.0-beta 251 10/23/2021
2021.10.1 6,483 9/30/2021
2021.10.0 282 9/30/2021
2021.10.0-beta.2 158 9/14/2021
2021.10.0-beta 190 9/13/2021
2021.9.3 2,246 9/12/2021
2021.9.2 336 9/1/2021
2021.9.1 212 9/1/2021
2021.9.0 207 8/30/2021
2021.8.0 2,048 8/2/2021
2021.5.2 1,719 5/5/2021
2021.4.0 417 4/2/2021
2021.3.1 6,497 3/1/2021
2021.3.0 231 3/1/2021
2021.2.0 252 2/8/2021
2021.1.0 285 1/4/2021
2020.11.0 3,409 11/1/2020

- Added support for generating documents in the XPS file format.