How to Print PDF to XPS in C#/VB.NET

Windows 7 comes with a Microsoft XPS Document Writer (MXDW) printer which can be used to print any document to an XPS file. It is also included in later releases, such as Windows 10. This article will introduce how to programmatically connect MXDW and print a PDF file into a XPS file.

To use following code snippets to print PDF file, you need to install Spire.PDF via NuGet and add the dll files into .NET assemblies.

Code Snippets

using Spire.Pdf;
namespace PrintPdfToXps
    class Program
        static void Main(string[] args)
            //load a Pdf document
            PdfDocument doc = new PdfDocument();

            //specify printer 
            doc.PrintDocument.PrinterSettings.PrinterName = "Microsoft XPS Document Writer";
            //print Pdf to a file instead a port
            doc.PrintDocument.PrinterSettings.PrintToFile = true;
            doc.PrintDocument.PrinterSettings.PrintFileName = "PrintToXps.xps";

            //start printing process