QuestPDF is a modern open-source .NET library for PDF document generation. Offering comprehensive layout engine powered by concise and discoverable C# Fluent API.
Document
.Create(document =>
{
document.Page(page =>
{
page.Size(PageSizes.Postcard);
page.Margin(0.3f, Unit.Inch);
page.Header()
.Text("Hello PDF!")
.FontSize(28)
.Bold()
.FontColor(Colors.Blue.Darken2);
page.Content()
.PaddingVertical(8)
.Column(column =>
{
column.Spacing(8);
column.Item()
.Text(Placeholders.LoremIpsum())
.Justify();
column.Item()
.AspectRatio(16 / 9f)
.Image(Placeholders.Image);
});
page.Footer()
.AlignCenter()
.Text(text =>
{
text.Span("Page ");
text.CurrentPageNumber();
});
});
})
.GeneratePdfAndShow();
GitHub stars guide developers toward great tools. If you find this project valuable, please give it a star – it helps the community and takes just a second! ⭐
Accelerate your development with live document preview powered by the hot-reload capability, eliminating the need for code recompilation:
- Explore document structure and hierarchy
- Quickly magnify and measure content
- Debug runtime exceptions with stack traces and code snippets
- Identify, understand and solve layout errors
Comprehensive Layout Engine
- A layout engine tailored for document generation, offering advanced paging and precise content control.
Rich Toolkit
- Craft documents with intuitive, reusable components and over 50 layout elements for complex designs.
High Performance
- Generate thousands of pages per second with minimal CPU and memory usage.
Advanced Language Support
- Seamlessly create multilingual documents with support for RTL, text shaping, and bi-directional content.
Using C# to design PDF documents leverages powerful control structures like if-statements, for-loops, and methods, enabling dynamic and highly customizable content generation.
It promotes best practices such as modular design and reusability while seamlessly integrating with source control systems for collaboration and versioning.
.Column(column =>
{
if (Model.Comments != null)
column.Item().Text(Model.Comments);
foreach(var item in Model.Items)
column.Item().Element(c => CreateItem(c, item);
});
void CreateItem(IContainer container, Item item)
{
container
- .Background(Colors.Grey.Lighten2)
+ .Background(item.Color)
.Padding(10)
.Text(item.Text);
}
The library supports all major operating systems, integrates seamlessly with leading IDEs as well as popular cloud platforms and technologies to ensure maximum flexibility.
Technologies
: modern dotnet, legacy .NET Framework, DockerOperating systems
: Windows, Linux, MacOSCloud providers
: Azure, AWS, Google CloudIDE
: Visual Studio, Visual Code, JetBrains Rider, others
- Merge documents
- Attach files
- Extract pages
- Encrypt / decrypt
- Extend metadata
- Limit access
- Optimize for Web
- Overlay / underlay
DocumentOperation
.LoadFile("input.pdf")
.TakePages("1-10")
.MergeFile("appendix.pdf", "1-z") // all pages
.AddAttachment(new DocumentAttachment
{
FilePath = "metadata.xml"
})
.Encrypt(new Encryption256Bit
{
OwnerPassword = "mypassword",
AllowPrinting = true,
AllowContentExtraction = false
})
.Save("final-document.pdf");
Follow our detailed tutorial, and see how easy it is to produce a fully functional invoice with fewer than 250 lines of C# code.
By offering free access to most users and premium licenses for larger organizations, the project maintains its commitment to excellence while ensuring sustainable, long-term development for all.
Warning
The library is free to use for any individual or business with less than 1 million USD annual gross revenue, or operates as a non-profit organization, or is a FOSS project.
We are incredibly grateful to the YouTube Community for their positive reviews and recommendations of the QuestPDF library. Your support and feedback are invaluable and motivate us to keep improving and expanding this project. Thank you for helping us grow and reach more developers!