How to Convert XAML to PDF in NET MAUI

Converting XAML to PDF in C# MAUI

IronPDF allows you to convert XAML pages to PDF in .NET MAUI applications with just a few lines of code. By using the RenderContentPageToPdf method, you can change your MAUI application's UI into professional PDF documents for desktop and web platforms.

.NET MAUI (Multi-platform App UI) is a cross-platform framework for building native device applications. It extends from Xamarin.Forms and is part of the unified .NET 6 ecosystem. It allows .NET application developers to create applications for desktop, web, and mobile platforms using common UI components and a single codebase. MAUI also lets you add platform-specific code and resources when necessary.

IronPDF lets you generate PDF documents from MAUI pages, making the creation of PDF files/pages possible in these applications. Whether you're developing on Windows or macOS, IronPDF provides consistent PDF generation capabilities. However, IronPDF currently does not support mobile platforms.

The PDF generation process in MAUI applications uses IronPDF's Chrome rendering engine, ensuring that your XAML layouts are accurately translated into PDF format. This makes it ideal for generating reports, invoices, or any document that needs to preserve the visual integrity of your MAUI application's user interface.

Quickstart: Convert XAML to PDF with IronPDF in .NET MAUI

Convert your XAML pages to PDF in .NET MAUI using IronPDF. With just a few lines of code, you can change your MAUI application's content into professional-quality PDF documents. This guide provides a straightforward example to get you started quickly, using IronPDF's efficient rendering capabilities. Follow along to integrate PDF generation smoothly into your desktop and web applications.

var pdf = new IronPdf.ChromePdfRenderer().RenderContentPageToPdf<MainPage,App>().SaveAs("page.pdf");
var pdf = new IronPdf.ChromePdfRenderer().RenderContentPageToPdf<MainPage,App>().SaveAs("page.pdf");
$vbLabelText   $csharpLabel

Minimal Workflow (5 steps)

  1. Download the IronPDF C# library for MAUI
  2. Modify the MainPage.xaml.cs file to use the RenderContentPageToPdf method
  3. Update the button in the MainPage.xaml file to trigger the new function
  4. Export the PDF document or view it in the MAUI app using a PDF viewer
  5. Download the sample MAUI project for a quick start

What Extension Package Do I Need for IronPDF with MAUI?

The IronPdf.Extensions.Maui package is the extension of the IronPdf main package. Since it is an extension, the IronPDF main package is still needed to render the content page of a MAUI application to a PDF document. This extension package specifically bridges the gap between MAUI's XAML-based UI framework and IronPDF's PDF generation capabilities.

The extension package handles the conversion of MAUI ContentPage objects into HTML that can be rendered as PDF. It preserves the layout and styling of your MAUI pages while providing access to all of IronPDF's advanced features like custom margins, custom paper sizes, and PDF compression.

Install-Package IronPdf.Extensions.Maui
Install-Package IronPdf.Extensions.Maui
SHELL

After installing the extension package, you'll gain access to the RenderContentPageToPdf method, which is the key to converting your MAUI pages. This method is optimized for performance and maintains the visual fidelity of your XAML layouts during the conversion process.

How Do I Render a MAUI Page to PDF?

Which Code File Should I Modify First?

  • Go from the MainPage.xaml file to its code file, MainPage.xaml.cs.
  • Change the function named OnCounterClicked to PrintToPdf. Use the code sample below.

To turn your MAUI page to a PDF, use the RenderContentPageToPdf method. The method can be accessed by instantiating the ChromePdfRenderer class. This method will give you a PdfDocument object, which you can save or view using the SaveAs method or a PDF viewer with Viewing PDFs in MAUI.

The ChromePdfRenderer class provides extensive customization options through its RenderingOptions property. You can set page margins, paper orientation, enable JavaScript execution, and much more. These options ensure that your PDF output matches your exact requirements.

:path=/static-assets/pdf/content-code-examples/how-to/xaml-to-pdf-maui-mainpage-xaml-cs.cs
using IronPdf.Extensions.Maui;

namespace mauiSample;

public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();
    }

    private void PrintToPdf(object sender, EventArgs e)
    {
        ChromePdfRenderer renderer = new ChromePdfRenderer();

        // Apply HTML header
        renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter()
        {
            HtmlFragment = "<h1>Header</h1>",
        };

        // Render PDF from Maui Page
        PdfDocument pdf = renderer.RenderContentPageToPdf<MainPage, App>().Result;

        pdf.SaveAs(@"C:\Users\lyty1\Downloads\contentPageToPdf.pdf");
    }
}
$vbLabelText   $csharpLabel

Furthermore, as you may have noticed, rendering from XAML also gives you full access to all the features available in RenderingOptions. This includes adding text and HTML headers and footers. You can also stamp images, add page numbers, and even customize the size and layout of the page. All these options are available when you use this method to create a PDF.

The RenderContentPageToPdf method is asynchronous by default, returning a Task<PdfDocument>. This allows for non-blocking PDF generation, which is particularly useful when dealing with complex layouts or when generating multiple PDFs simultaneously. The method automatically handles the conversion of XAML visual elements to their PDF equivalents, preserving colors, fonts, and layout structures.

What Changes Do I Need in the XAML File?

In the MainPage.xaml file, replace the default OnCounterClicked function with the new PrintToPdf function. Clicking this button will run the PrintToPdf method and create the PDF. This simple modification transforms your MAUI application into a PDF generator with minimal code changes.

<Button
    x:Name="PrintToPdfBtn"
    Text="Print to pdf"
    SemanticProperties.Hint="Click to print page as PDF"
    Clicked="PrintToPdf"
    HorizontalOptions="Center" />
<Button
    x:Name="PrintToPdfBtn"
    Text="Print to pdf"
    SemanticProperties.Hint="Click to print page as PDF"
    Clicked="PrintToPdf"
    HorizontalOptions="Center" />
XML

The button can be styled using standard MAUI styling properties, and you can add additional visual feedback like loading indicators while the PDF is being generated. This ensures a smooth user experience during the PDF creation process.

What Does the Output PDF Look Like?

Before you save your PDF file, you can make more changes to it using the methods available to PdfDocument. You can merge pages, split them apart, or rotate them. You can also add annotations and bookmarks to your PDF. Additionally, you can set PDF metadata such as author, title, and keywords to improve document organization and searchability.

The generated PDF maintains the visual hierarchy and styling of your MAUI page, including fonts, colors, and layout constraints. This makes it perfect for creating printable versions of your application's screens or generating reports based on your app's UI.

Where Can I Download a Complete MAUI Sample Project?

You can download the complete code for this guide. It comes as a zipped file that you can open in Visual Studio as a .NET MAUI App project. The sample project includes all the necessary dependencies and demonstrates best practices for integrating IronPDF into your MAUI applications.

The sample project is configured to work on both Windows and macOS desktop platforms, showcasing the cross-platform capabilities of both MAUI and IronPDF. It includes examples of various PDF generation scenarios and demonstrates how to handle different page layouts and content types.

Download the Full MAUI Sample Project

Explore more possibilities with our tutorial page here: Convert PDFs. You might also be interested in exploring our guides on PDF compression to improve your generated PDFs for web distribution, or learn about creating PDFs in Blazor Servers for web-based PDF generation scenarios.

Frequently Asked Questions

What is .NET MAUI and how does it relate to PDF generation?

.NET MAUI (Multi-platform App UI) is a cross-platform framework for building native device applications that extends from Xamarin.Forms. IronPDF integrates with .NET MAUI applications to enable PDF generation from XAML pages using the RenderContentPageToPdf method, allowing developers to transform their MAUI application's UI into professional PDF documents.

Which platforms are supported for PDF generation in MAUI applications?

IronPDF currently supports PDF generation in MAUI applications on desktop (Windows and macOS) and web platforms. Mobile platforms are not currently supported by IronPDF for MAUI PDF generation.

What extension package is required for converting XAML to PDF in MAUI?

You need the IronPdf.Extensions.Maui package along with the main IronPdf package. The extension package specifically bridges MAUI's XAML-based UI framework with IronPDF's PDF generation capabilities, handling the conversion of MAUI ContentPage objects into HTML that can be rendered as PDF.

How do I convert a MAUI XAML page to PDF in C#?

Converting a MAUI XAML page to PDF with IronPDF is simple. You can use the RenderContentPageToPdf method with just one line of code: var pdf = new IronPdf.ChromePdfRenderer().RenderContentPageToPdf().SaveAs('page.pdf'). This leverages IronPDF's Chrome rendering engine to accurately translate XAML layouts into PDF format.

What are the basic steps to implement PDF generation in a MAUI application?

The basic workflow includes: 1) Download the IronPDF C# library for MAUI, 2) Modify the MainPage.xaml.cs file to use the RenderContentPageToPdf method, 3) Update the button in MainPage.xaml to trigger the function, 4) Export the PDF document or view it in the MAUI app, and 5) Optionally download IronPDF's sample MAUI project for a quick start.

What rendering engine does the PDF conversion process use?

IronPDF uses its Chrome rendering engine for the PDF generation process in MAUI applications. This ensures that your XAML layouts are accurately translated into PDF format while preserving the visual integrity of your MAUI application's user interface.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...

Read More
Ready to Get Started?
Nuget Downloads 17,012,929 | Version: 2025.12 just released