2022.12
版本发布时间: 2022-12-14 20:54:35
QuestPDF/QuestPDF最新发布版本:2024.7.3(2024-08-27 22:56:00)
QuestPDF offers a layout engine designed 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 behavior 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.
To learn how easy it is to design documents with the library, let's quickly 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.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");
And compare it to the produced PDF file:
Please help by giving a star
⭐ Please consider giving a start to this repository. It takes seconds and helps thousands of developers! ⭐
What's new? 🎊
This QuestPDF release is special as it mainly consists of features proposed and developed by the community:
-
Feature: implemented LetterSpacing property for the Text element (implemeneted by @Bebo-Maker in #398)
-
Improvement: the Text element API accepts now only string values, objects are not automatically converted anymore (proposed by @rstm-sf in #362)
-
Fix: the Alignment element incorrectly limits size of its child when only one axis is set: horizontal or vertical (found by @zlatanov in #401)
-
Maintenance: Updated SkiaSharp dependency to 2.88.3. Updated Avalonia dependency in the QuestPDF.Previewer project to the latest version. (this was a long awaiting effort that should improve experience for many developers)
-
Development: Implemented usage on GitHub Actions to trigger automated solution build after every commit. This build is also used for packing nuget artifacts. It is a great starting point for future improvements. (proposed by @rstm-sf in #366)
Let me thank you all for your help!
Letter spacing
Letter spacing allows to increase or decrease space between characters. This setting is useful when you want to make the text more compact (by decreasing letter spacing) or easier to read (by increasing letter spacing):
- Value 0 corresponds to normal spacing defined by a font.
- Positive values create additional space.
- Negative values reduce space between characters.
This settings uses relative units. Example: let's assume your text has font size 20. If letter spacing is set to 0.1, an additional space of 2 points will be added between characters.
.Column(column =>
{
var letterSpacing = new[] { -0.05f, 0f, 0.2f };
var paragraph = Placeholders.Sentence();
foreach (var spacing in letterSpacing)
{
column
.Item()
.Border(1)
.Padding(10)
.Column(nestedColumn =>
{
nestedColumn
.Item()
.Text(paragraph)
.FontSize(18)
.LetterSpacing(spacing); // <- here 😊
nestedColumn
.Item()
.Text($"Letter spacing of {spacing} em")
.FontSize(14)
.Italic()
.FontColor(Colors.Blue.Medium);
});
}
});