1. Products
  2.   PDF
  3.   .NET
  4.   QuestPDF
 
  

Free .NET APIs for PDF Documents Processing

Open Source .NET Library for creating, editing, loading and manipulating PDFs. Add new pages, tables, images, Text and shapes to PDF Files.

QuestPDF is a very useful open source modern .NET library that allows software developers to generate, read, modify and manipulate PDF documents with ease. The library is very feature rich and offers lay-outing engine designed with a full paging support in mind. The library is very easy to handle and can surely speed up your development lifecycle. The library support hot-reload capability which means it provides developers the real-time results without the need of code recompilation.

The QuestPDF library is very fluent and very easy to create, customize, and manage some of the most complex documents with just couple of lines of code. There are several other features part of the library such as draw simple text, draw text with custom styling, paging support, custom fonts support, letter spacing, custom paragraphs spacing, Unicode support, inserting images, manage image's aspect ratio, renders border, inserting hyperlinks, content and image rotation and so on.

Previous Next

Getting Started with QuestPDF

The QuestPDF library is available as a nuget package. So it is highly recommend using NuGet to install QuestPDF to your project. Please use the following command for successful installation.

Install QuestPDF from Nuget

// Package Manager
Install-Package QuestPDF

// .NET CLI
dotnet add package QuestPDF

// Package reference in .csproj file

You can also install it manually; download the latest release files directly from GitHub repository.

Easy PDF Creation via .NET Library

The open source PDF library QuestPDF enables software developers to use just a couple of simple .NET code commands to create a PDF documents inside their own applications. The library makes it easy for developers to define page size, margins, background color, text style, font’s size, page header and footer, page content, spacing and so on. It is also very easy to update your existing PDF files.

Create PDF Files via .NET Library

 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.PageColor(Colors.White);
        page.DefaultTextStyle(x => x.FontSize(20));
        
        page.Header()
            .Text("Hello PDF!")
            .SemiBold().FontSize(36).FontColor(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");

Manage Text & Formatting via C# API

The QuestPDF library has provided several important features for handling text inserting as well text drawing inside PDF documents. It enables developers to draw text with default styling as well as custom styling, subscript and superscript, adjust text lines, adjust letter spacing, font alignment, set typography pattern, custom paragraph spacing, setting text direction, inject page numbers, add hyperlink and so on.

Subscript and Superscript in PDF Files via .NET Library

 .Text(text =>
{
    text.DefaultTextStyle(x => x.FontSize(20));
    text.ParagraphSpacing(10);

    var highlight = TextStyle.Default.BackgroundColor(Colors.Green.Lighten3);

    text.Span("E=mc").Style(highlight);
    text.Span("2").Superscript().Style(highlight);
    text.Span(" is the equation of mass–energy equivalence.");

    text.EmptyLine();
    
    text.Span("H").Style(highlight);
    text.Span("2").Subscript().Style(highlight);
    text.Span("O").Style(highlight);
    text.Span(" is the chemical formula for water.");
}); 

Add & Manage Images in PDF via C# Library

The open source PDF library QuestPDF has included complete support for adding static as well dynamic images inside C# .NET applications. Software developers can easily place static images inside their PDF document in any common raster image format, like JPG, PNG, BMB, and so on. For dynamic images it offers flexible layouts, therefore it is hard to predict image resolution. To get best image clarity, it is recommended to generate images with specified resolution. It is very useful for creating maps / charts.

Add Images to PDF via .NET Library

 // it is possible to provide an image as:
 
// 1) a binary array
byte[] imageData = File.ReadAllBytes("path/to/logo.png")
container.Image(imageData)

// 2) a fileName
container.Image("path/myFile.png")

// 3) a stream
using var stream = new FileStream("logo.png", FileMode.Open);
container.Image(stream); 

Insert Tables in PDF via C# API

The QuestPDF enables computer programmers to achieve more sophisticated structures than any combination of the Row and the Column elements. To create a simple table instance users needs to describe the width of each column and then place any number of rows and columns inside it. The library supports features like add table header or footer, add new rows, insert new cells, remove cells, Row spans and column spans, lverlapping cells and many more.

Create Simple Table in PDF File via .NET Library

 .Border(1)
.Table(table =>
{
    table.ColumnsDefinition(columns =>
    {
        columns.RelativeColumn();
        columns.RelativeColumn();
        columns.RelativeColumn();
        columns.RelativeColumn();
    });

    // by using custom 'Element' method, we can reuse visual configuration
    table.Cell().Row(1).Column(4).Element(Block).Text("A");
    table.Cell().Row(2).Column(2).Element(Block).Text("B");
    table.Cell().Row(3).Column(3).Element(Block).Text("C");
    table.Cell().Row(4).Column(1).Element(Block).Text("D");
    
    // for simplicity, you can also use extension method described in the "Extending DSL" section
    static IContainer Block(IContainer container)
    {
        return container
            .Border(1)
            .Background(Colors.Grey.Lighten3)
            .ShowOnce()
            .MinWidth(50)
            .MinHeight(50)
            .AlignCenter()
            .AlignMiddle();
    }
});
 English