Generate and edit PDF documents in your .NET applications using the open-source QuestPDF library and its C# Fluent API. Build invoices, reports and data exports with ease.

www.questpdf.com

Topics
#html #csharp #export #pdf #library #nuget #report #dotnetcore #dotnet #generation #invoice #document #form #generation

MarcinZiabek 1b9b164583 DefaultTextStyle API improvements 3 年之前
.github ba409a8712 Create codeql-analysis.yml 3 年之前
QuestPDF 1b9b164583 DefaultTextStyle API improvements 3 年之前
QuestPDF.Examples 1b9b164583 DefaultTextStyle API improvements 3 年之前
QuestPDF.ReportSample b533a32b61 Text API naming adjustments 3 年之前
QuestPDF.UnitTests b533a32b61 Text API naming adjustments 3 年之前
.gitignore 8326446446 Library implementation 5 年之前
CODE_OF_CONDUCT.md 6b6d2d7fa3 Create CODE_OF_CONDUCT.md 4 年之前
LICENSE 3e3c464974 Initial commit 5 年之前
QuestPDF.sln 8326446446 Library implementation 5 年之前
SECURITY.md 20fe49dd01 Update SECURITY.md 4 年之前
readme.md fcff989ab2 Improved text API 3 年之前

readme.md

QuestPDF presents a new approach to PDF document generation. Unlike other libraries, it does not rely on the HTML-to-PDF conversion which in many cases is not reliable. Instead, it implements its own layouting engine that is optimized to cover all paging-related requirements. Then, everything is rendered using the SkiaSharp library (a Skia port for .NET, used in Chrome, Android, MAUI, etc.).

I have designed this layouting engine with full paging support in mind. The document consists of many simple elements (e.g. border, background, image, text, padding, table, grid etc.) that are composed together to create more complex structures. This way, as a developer, you can understand the behaviour of every element and use them with full confidence. Additionally, the document and all its elements support paging functionality. For example, an element can be moved to the next page (if there is not enough space) or even be split between pages like table's rows.

Support QuestPDF

All great frameworks and libraries started from zero. Please help me make QuestPDF a commonly known library and an obvious choice for generating PDF documents.

  • ⭐ Give this repository a star,
  • 💬 Share it with your team members.

Installation

The library is available as a nuget package. You can install it as any other nuget package from your IDE, try to search by QuestPDF. You can find package details on this webpage.

// Package Manager
Install-Package QuestPDF

// .NET CLI
dotnet add package QuestPDF

// Package reference in .csproj file
<PackageReference Include="QuestPDF" Version="2022.2.5" />

Documentation

🚀 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 create reusable code that is easy to maintain.

Simplicity is the key

How easy it is to start and prototype with QuestPDF? Really easy thanks to its minimal API! Please analyse the code below:

using QuestPDF.Fluent;
using QuestPDF.Helpers;
using QuestPDF.Infrastructure;

// code in your main method
Document.Create(container =>
{
    container.Page(page =>
    {
        page.Size(PageSizes.A4);
        page.Margin(2, Unit.Centimetre);
        page.Background(Colors.White);
        page.DefaultTextStyle(TextStyle.Default.Size(20));
        
        page.Header()
            .Text("Hello PDF!", TextStyle.Default.SemiBold().Size(36).Color(Colors.Blue.Medium));
        
        page.Content()
            .PaddingVertical(1, Unit.Centimetre)
            .Column(x =>
            {
                x.Spacing(20);
                
                x.Item().Text(Placeholders.LoremIpsum());
                x.Item().Image(Placeholders.Image(200, 100));
            });
        
        page.Footer()
            .AlignCenter()
            .Text(x =>
            {
                x.Span("Page ");
                x.CurrentPageNumber();
            });
    });
})
.GeneratePdf("hello.pdf");

And compare it to the produced PDF file:

Are you ready for more?

The Fluent API of QuestPDF scales really well. It is easy to create and maintain even most complex documents. Read the Getting started tutorial to learn QuestPDF basics and implement an invoice under 200 lines of code. You can also investigate and play with the code from the example repository.