QuestPDF Report Generation
Overview
QuestPDF is a modern C# library for PDF document generation with a dedicated layout engine optimized for PDF creation. It uses a component-based, fluent API architecture where simple elements are composed into sophisticated documents.
Key Benefits
| Feature |
Description |
| Native C# API |
No HTML-to-PDF conversion - direct PDF generation |
| Component-Based |
Reusable IComponent pattern for modular documents |
| Automatic Pagination |
Content flows naturally across pages |
| Type-Safe |
Compile-time checked document structure |
| Fluent API |
Intuitive chaining syntax for layout definition |
Installation
dotnet add package QuestPDF
License: Free for individuals, non-profits, and businesses < $1M annual revenue.
Quick Start
using QuestPDF.Fluent;
using QuestPDF.Infrastructure;
using QuestPDF.Helpers;
Document.Create(container =>
{
container.Page(page =>
{
page.Size(PageSizes.A4);
page.Margin(50);
page.Header().Text("My Report").FontSize(24).Bold();
page.Content().Column(column =>
{
column.Spacing(10);
column.Item().Text("Hello, QuestPDF!");
column.Item().Text($"Generated: {DateTime.Now:g}");
});
page.Footer().AlignCenter().Text(text =>
{
text.Span("Page ");
text.CurrentPageNumber();
text.Span(" of ");
text.TotalPages();
});
});
}).GeneratePdf("report.pdf");
Common Pitfalls
| Pitfall |
Solution |
| Constraint conflicts |
Ensure parent containers provide sufficient space for width/height constraints |
| Header/Footer height |
Combined header + footer must leave space for content |
| Image loading |
Load images once and reuse for performance |
| Text overflow |
Use .ClampLines() or ensure adequate width |
| DateTime metadata |
Use DateTimeOffset.Now instead of DateTime.Now |
Additional Resources
For detailed guidance, see:
- Document Architecture - IDocument pattern, models, three-layer architecture
- Layout Components - Column, Row, Table, Inlined, Layers, Decoration
- Text & Styling - Fonts, typography, colors, DefaultTextStyle
- Tables - Table structure, headers, footers, cell spanning, styling
- Images & Media - Loading, scaling, SVG, optimization
- Page Flow - Page breaks, sections, navigation, conditional rendering
- Report Patterns - Invoices, data tables, reusable components
API Reference
For complete API documentation, see: https://www.questpdf.com/api-reference/
1---2name: questpdf3description: QuestPDF report generation with fluent C# API. Use when generating PDF documents, designing report layouts, creating invoices/data tables, implementing page structures with headers/footers, or building reusable document components.4---5
6# QuestPDF Report Generation
7
8## Overview
9
10QuestPDF is a modern C# library for PDF document generation with a dedicated layout engine optimized for PDF creation. It uses a component-based, fluent API architecture where simple elements are composed into sophisticated documents.
11
12### Key Benefits
13
14| Feature | Description |
15|---------|-------------|
16| **Native C# API** | No HTML-to-PDF conversion - direct PDF generation |
17| **Component-Based** | Reusable IComponent pattern for modular documents |
18| **Automatic Pagination** | Content flows naturally across pages |
19| **Type-Safe** | Compile-time checked document structure |
20| **Fluent API** | Intuitive chaining syntax for layout definition |
21
22## Installation
23
24```bash
25dotnet add package QuestPDF
26```
27
28**License:** Free for individuals, non-profits, and businesses < $1M annual revenue.
29
30## Quick Start
31
32```csharp
33using QuestPDF.Fluent;
34using QuestPDF.Infrastructure;
35using QuestPDF.Helpers;
36
37Document.Create(container =>
38{
39 container.Page(page =>
40 {
41 page.Size(PageSizes.A4);
42 page.Margin(50);
43
44 page.Header().Text("My Report").FontSize(24).Bold();
45
46 page.Content().Column(column =>
47 {
48 column.Spacing(10);
49 column.Item().Text("Hello, QuestPDF!");
50 column.Item().Text($"Generated: {DateTime.Now:g}");
51 });
52
53 page.Footer().AlignCenter().Text(text =>
54 {
55 text.Span("Page ");
56 text.CurrentPageNumber();
57 text.Span(" of ");
58 text.TotalPages();
59 });
60 });
61}).GeneratePdf("report.pdf");
62```
63
64## Common Pitfalls
65
66| Pitfall | Solution |
67|---------|----------|
68| Constraint conflicts | Ensure parent containers provide sufficient space for width/height constraints |
69| Header/Footer height | Combined header + footer must leave space for content |
70| Image loading | Load images once and reuse for performance |
71| Text overflow | Use `.ClampLines()` or ensure adequate width |
72| DateTime metadata | Use `DateTimeOffset.Now` instead of `DateTime.Now` |
73
74## Additional Resources
75
76For detailed guidance, see:
77- [Document Architecture](document-architecture.md) - IDocument pattern, models, three-layer architecture
78- [Layout Components](layout-components.md) - Column, Row, Table, Inlined, Layers, Decoration
79- [Text & Styling](text-styling.md) - Fonts, typography, colors, DefaultTextStyle
80- [Tables](tables.md) - Table structure, headers, footers, cell spanning, styling
81- [Images & Media](images-media.md) - Loading, scaling, SVG, optimization
82- [Page Flow](page-flow.md) - Page breaks, sections, navigation, conditional rendering
83- [Report Patterns](report-patterns.md) - Invoices, data tables, reusable components
84
85## API Reference
86
87For complete API documentation, see: https://www.questpdf.com/api-reference/