GemBox.Presentation is a .NET component that enables you to read, write, edit, convert, and print presentation files from your .NET applications using one simple API.

Export PowerPoint to XpsDocument in WPF

Following example shows how to convert PowerPoint presentation to XpsDocument instance and attach it to WPF's DocumentViewer control.

Screenshot
Export to XpsDocument / DocumentViewer Control Screenshot

See the full code below.

<Window x:Class="ConvertToXpsDocumentCs.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Export to XpsDocument Sample" 
        SizeToContent="WidthAndHeight">

    <DocumentViewer x:Name="DocumentViewer"/>
    
</Window>
using System.Windows;
using System.Windows.Controls;
using System.Windows.Xps.Packaging;
using GemBox.Presentation;

namespace ConvertToXpsDocumentCs
{
    public partial class MainWindow : Window
    {
        XpsDocument xpsDocument;

        public MainWindow()
        {
            InitializeComponent();

            this.SetDocumentViewer(this.DocumentViewer);
        }

        private void SetDocumentViewer(DocumentViewer documentViewer)
        {
            ComponentInfo.SetLicense("FREE-LIMITED-KEY");

            PresentationDocument presentation = new PresentationDocument();

            Slide slide = presentation.Slides.AddNew(SlideLayoutType.Custom);

            GemBox.Presentation.TextBox textBox = slide.Content.AddTextBox(
                ShapeGeometryType.Rectangle, 2, 2, 8, 4, LengthUnit.Centimeter);
            textBox.Shape.Format.Outline.Fill.SetSolid(Color.FromName(ColorName.DarkGray));

            TextRun run = textBox.AddParagraph().AddRun("Hello World!");
            run.Format.Fill.SetSolid(Color.FromName(ColorName.Black));

            // XpsDocument needs to stay referenced so that DocumentViewer 
            // can access additional required resources.
            // Otherwise, GC will collect/dispose XpsDocument and DocumentViewer 
            // will not work.
            this.xpsDocument = presentation.ConvertToXpsDocument(SaveOptions.Xps);

            documentViewer.Document = this.xpsDocument.GetFixedDocumentSequence();
        }
    }
}
Imports System.Windows.Xps.Packaging
Imports GemBox.Presentation

Class MainWindow

    Dim xpsDocument As XpsDocument

    Public Sub New()
        InitializeComponent()

        SetDocumentViewer(Me.DocumentViewer)
    End Sub

    Private Shared Sub SetDocumentViewer(documentViewer As DocumentViewer)

        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        Dim presentation = New PresentationDocument()

        Dim slide As Slide = presentation.Slides.AddNew(SlideLayoutType.Custom)

        Dim textBox As TextBox = slide.Content.AddTextBox(
            ShapeGeometryType.Rectangle, 2, 2, 8, 4, LengthUnit.Centimeter)
        textBox.Shape.Format.Outline.Fill.SetSolid(Color.FromName(ColorName.DarkGray))

        Dim run As TextRun = textBox.AddParagraph().AddRun("Hello World!")
        run.Format.Fill.SetSolid(Color.FromName(ColorName.Black))

        Dim xpsDocument = presentation.ConvertToXpsDocument(SaveOptions.Xps)
        documentViewer.Document = xpsDocument.GetFixedDocumentSequence()

        ' XpsDocument needs to stay referenced so that DocumentViewer 
        ' can access additional required resources.
        ' Otherwise, GC will collect/dispose XpsDocument and DocumentViewer 
        ' will not work.
        xpsDocument = presentation.ConvertToXpsDocument(SaveOptions.Xps)

        documentViewer.Document = xpsDocument.GetFixedDocumentSequence()

    End Sub

End Class

Check next sample.