Skip to content
If you like QuestPDF, please give it a star on GitHub.
It takes seconds and helps others make the right choice!

Text

Simple usage

In most cases, text content can be added using the following shorthand. The text will inherit the default style.

c#
container
    .Text("Hello, World!");

example

Customization

The Text method returns a descriptor that allows further customization of the text style.

c#
.Column(column =>
{
    column.Spacing(10);

    column.Item()
        .Element(CellStyle)
        .Text("Text with blue color")
        .FontColor(Colors.Blue.Darken1);

    column.Item()
        .Element(CellStyle)
        .Text("Bold and underlined text")
        .Bold()
        .Underline();

    column.Item()
        .Element(CellStyle)
        .Text("Centered small text")
        .FontSize(12)
        .AlignCenter();

    static IContainer CellStyle(IContainer container) =>
        container.Background(Colors.Grey.Lighten3).Padding(10);
});

example

Rich text formatting

It is also possible to format specific parts of the text content using spans:

c#
container
    .Text(text =>
    {
        text.Span("The ");
        text.Span("chemical formula").Underline();
        text.Span(" of ");
        text.Span("sulfuric acid").BackgroundColor(Colors.Amber.Lighten3);
        text.Span(" is H");
        text.Span("2").Subscript();
        text.Span("SO");
        text.Span("4").Subscript();
        text.Span(".");
    });

example

Typography pattern

The typography pattern helps maintain consistent text styling across your documents.

c#
public static class Typography
{
    public static TextStyle Title => TextStyle
        .Default
        .FontType("Helvetica")
        .FontColor(Colors.Black)
        .FontSize(20)
        .Bold();

    public static TextStyle Headline => TextStyle
        .Default
        .FontType("Helvetica")
        .FontColor(Colors.Blue.Medium)
        .FontSize(14);

    public static TextStyle Normal => TextStyle
        .Default
        .FontType("Helvetica")
        .FontColor("#000000")
        .FontSize(10)
        .LineHeight(1.25f)
        .AlignLeft();
}

Then, a predefined typography can be used in the following way:

c#
container
    .Text("Report #123")
    .Style(Typography.Title);
    
// instead of

container    
    .Text("Report #123")
    .FontType("Helvetica")
    .FontColor(Colors.Black)
    .FontSize(20)
    .Bold();

Hyperlink is a clickable text that redirects the user to a specific webpage.

c#
.Text(text =>
{
    var hyperlinkStyle = TextStyle.Default
        .FontColor(Colors.Blue.Medium)
        .Underline();

    text.Span("To learn more about QuestPDF, please visit its ");
    text.Hyperlink("homepage", "https://www.questpdf.com/").Style(hyperlinkStyle);
    text.Span(", ");
    text.Hyperlink("GitHub repository", "https://github.com/QuestPDF/QuestPDF").Style(hyperlinkStyle);
    text.Span(" and ");
    text.Hyperlink("NuGet package page", "https://www.nuget.org/packages/QuestPDF").Style(hyperlinkStyle);
    text.Span(".");
});

Unable to display PDF file. Download instead.

Released under the MIT License