DEV Community

Cover image for Tired of Multiple Viewers? Build a Universal Document Viewer in .NET MAUI
Calvince Moth for Syncfusion, Inc.

Posted on • Originally published at syncfusion.com on

Tired of Multiple Viewers? Build a Universal Document Viewer in .NET MAUI

TL;DR: Multi‑format document handling in apps doesn’t need separate viewers. By converting Word, Excel, PowerPoint, Images, and XPS into PDF, the .NET MAUI PDF Viewer becomes a universal document hub. Developers get one streamlined interface for previewing, annotating, and collaborating across formats. The result: simpler workflows, consistent user experience, reduced complexity, and scalable cross‑platform document management.

The big idea: PDF as the universal document viewer layer

Modern cross-platform apps rarely deal with “ just PDFs.” Users open Word docs, Excel sheets, PowerPoint decks, images, and even XPS files, often inside the same workflow. The problem: building and maintaining a separate viewer per format is costly, inconsistent across platforms, and hard to scale.

To create a smoother workflow, adopt a simpler approach: standardize PDF as the universal document viewer format. By converting incoming files to PDF, you enable seamless rendering through a single PDF Viewer component.

With this strategy in mind, this blog will guide you through setting up a unified document viewing workflow for your .NET MAUI apps.

Why convert everything to PDF?

PDF is a stable, layout-preserving format that works well for preview and review scenarios:

  • Consistent UI rendering across mobile and desktop apps.
  • One viewer instead of multiple format-specific viewers.
  • Safe review workflows (annotations instead of editing the original).
  • Easier enterprise controls (stream-based loading, reduced file persistence).

The star of the show: Syncfusion .NET MAUI PDF Viewer

The Syncfusion® .NET MAUI PDF Viewer natively supports PDF files and offers a rich interaction model. When combined with Syncfusion Document Processing Libraries, it becomes a complete, universal document viewing engine.

Once all documents are converted to PDF, the .NET MAUI PDF Viewer presents a single, consistent UI across all formats.

What you can preview: Supported document types

The Syncfusion .NET MAUI PDF Viewer supports converting and previewing the following five commonly used file types into PDF format:

  1. Word documents
  2. Excel workbooks
  3. PowerPoint presentations
  4. Images
  5. XPS files

Behind the scenes: Document conversion engine stack

To convert various file formats into PDF, Syncfusion offers a range of document processing libraries. Depending on the file type and your specific requirements, one or more of these libraries can be used:

Each library handles format‑specific conversion, producing a PdfDocument object that can be passed to the viewer. Using this approach maintains high fidelity and preserves layouts.

Essential setup and configuration

  1. First, we need to establish the foundation by creating a new .NET MAUI app. Then, install the required packages for the .NET MAUI PDF Viewer and document processing libraries. Here’s the code you need:
<PackageReference Include="Syncfusion.DocIORenderer.NET" Version="*" />
<PackageReference Include="Syncfusion.Maui.PdfViewer" Version="*" />
<PackageReference Include="Syncfusion.Maui.TabView" Version="*" />
<PackageReference Include="Syncfusion.Pdf.Imaging.NET" Version="*" />
<PackageReference Include="Syncfusion.Presentation.NET" Version="*" />
<PackageReference Include="Syncfusion.PresentationRenderer.NET" Version="*" />

\<PackageReference Include="Syncfusion.XlsIORenderer.NET" Version="*" />8
<PackageReference Include="Syncfusion.XpsToPdfConverter.NET" Version="*" />

Enter fullscreen mode Exit fullscreen mode
  1. Next, configure the handlers in the MauiProgram.cs file as shown in the code below:
using Syncfusion.Maui.Core.Hosting;

public static MauiApp CreateMauiApp()
{
    var builder = MauiApp.CreateBuilder();
    builder
        .UseMauiApp<App>()
        .ConfigureSyncfusionCore();

    return builder.Build();
}
Enter fullscreen mode Exit fullscreen mode

Building a universal document viewer in .NET MAUI

Let’s see the steps to build a seamless universal document viewing experience using the Syncfusion .NET MAUI PDF Viewer:

Step 1: Handle format-specific PDF conversions

Once the required Syncfusion libraries are configured, implement the logic to convert each supported file type into a PDF.

Below is a breakdown of the conversion logic for each supported format:

Word to PDF

To convert a Word document, use the DocIORenderer.ConvertToPDF(WordDocument) method, which converts a loaded WordDocument into a PdfDocument.

Refer to the example below.

// Loading an existing Word document
Assembly assembly = typeof(App).GetTypeInfo().Assembly;

using (WordDocument document = new WordDocument(
    assembly.GetManifestResourceStream("SampleName.Assets.InputDocument.docx"),
    FormatType.Docx))
{
    // Convert to PDF using DocIO's rendering engine
    using (DocIORenderer renderer = new DocIORenderer())
    {
        PdfDocument pdfDocument = renderer.ConvertToPDF(document);
        // Proceed to save as stream
    }
}
Enter fullscreen mode Exit fullscreen mode

Note: You can check out more options and examples in the Word to PDF conversion guide.

Excel to PDF

Excel workbooks can be converted using the XlsIORenderer.ConvertToPDF(IWorkbook) method, which converts an IWorkbook (Excel document) into a PdfDocument.

Here’s the code example for quick conversion:

// Initialize Excel engine and open workbook
using (ExcelEngine excelEngine = new ExcelEngine())
{
    IApplication application = excelEngine.Excel;
    IWorkbook workbook = application.Workbooks.Open(
        assembly.GetManifestResourceStream("SampleName.Assets.InputDocument.xlsx"));

    // Convert workbook to PDF
    XlsIORenderer renderer = new XlsIORenderer();
    PdfDocument pdfDocument = renderer.ConvertToPDF(workbook);

    // Proceed to save as stream
}
Enter fullscreen mode Exit fullscreen mode

Note: You can check out more options and examples in the Excel to PDF conversion guide.

PowerPoint to PDF

For PowerPoint presentations, the PresentationToPdfConverter.Convert(IPresentation) method handles the conversion of an IPresentation (PowerPoint presentation) object into a PdfDocument.

Please refer to the complete code block:

// Open PowerPoint presentation
using (IPresentation presentation = Presentation.Open(
    assembly.GetManifestResourceStream("SampleName.Assets.InputDocument.pptx")))
{
    // Convert slides to PDF pages
    PdfDocument pdfDocument = PresentationToPdfConverter.Convert(presentation);
    // Proceed to save as stream
}
Enter fullscreen mode Exit fullscreen mode

Note: You can check out more options and examples in the PowerPoint to PDF conversion documentation.

Image to PDF

For image conversion, the PdfGraphics.DrawImage() method facilitates the conversion of images to PDF by drawing a PdfBitmap onto a PDF page. You can load images from various sources using the PdfBitmap class.

// Create a new PDF and add a page
PdfDocument document = new PdfDocument();

// Add a page to the document
PdfPage page = document.Pages.Add();
PdfGraphics graphics = page.Graphics;

// Load the image from the disk
FileStream imageStream = new FileStream("Autumn Leaves.jpg", FileMode.Open, FileAccess.Read);
PdfBitmap image = new PdfBitmap(imageStream);

// Draw the image
graphics.DrawImage(image, 0, 0);
Enter fullscreen mode Exit fullscreen mode

Note: For more details, refer to the Image to PDF Conversion guide.

XPS to PDF

XPS documents can be converted using the XPSToPdfConverter.Convert(Stream) method, which converts an XPS file stream into a PdfDocument, preserving the document layout and the visual appearance of each page.

Code snippet to achieve this:

// Load XPS file and convert to PDF
XPSToPdfConverter converter = new XPSToPdfConverter();

using (FileStream xpsStream = new FileStream("sample.xps", FileMode.Open, FileAccess.ReadWrite))
{
    PdfDocument pdfDocument = converter.Convert(xpsStream);
    // Proceed to save as stream
}
Enter fullscreen mode Exit fullscreen mode

Note: For detailed information, refer to the XPS to PDF conversion documentation.

This article was originally published at Syncfusion.com.

Top comments (0)