Design PDF in .NET MAUI XAML with DrawnUI
A report, a statement, or a certificate often has to leave the app as a PDF. Nick Kovalsky shows how to define that document as a DrawnUI layout in XAML — the same bindings and controls as a screen — and render it onto paper with SkiaSharp.
What you’ll learn
- Where this fits among the other options — a document API such as Gerald Versluis’s iText sample when the file is text and images, a band-based engine such as Pysar for invoices, and a drawn layout when the PDF should reuse the app’s charts, maps, and custom paint
- The report as a page — a
SkiaLayoutcolumn bound to a view model, noUseCacheinside the report so text stays vectors, andMauiXamlInflatorset toSourceGenso a long table does not inflate through reflection in a Debug build - Paper units — portrait A4 at 150 dpi via DrawnUI’s
Pdfhelper, margins in inches, and font sizes that print at a known point size - The export loop — create the report off any
Canvas, measure at page width with unlimited height, and warm up into anSKPictureRecorderuntil async images and map tiles reportContentIsLoaded - Page breaks that respect rows —
Pdf.SplitStackToPagessplits a templated column between items, then each page is drawn intoSKDocumentin points (72 per inch) so the file is a real A4 - Beyond MAUI — the same report in code-behind works for Blazor or a plain .NET server with
DrawnUi.Net
Open the post for the RepoReport sample, which fills a multi-page report from the GitHub API, and for the Racebox production report that started the technique.