How to convert XPS file to Bitmap

XPS stands for XML Paper Specification and is basically an electronic representation of digital documents based on XML. An XpsDocument contains a FixedDocumentSequence that comprises one or more FixedDocument elements. They are also easy to share because you can view them on any computer where an XPS viewer is installed, even if the computer does not have the same programs that you used to create the original documents.

The following C# program convert and xps document to a bitmap image. Create a new C# project and add a Button to Form and add the following references to your project.

Go to Project->Add References and select these files from .Net tab.

  1. windowsbase.dll
  2. ReachFramework.dll
  3. PresentationFramework.dll
  4. Milk
  5. PresentationCore.dll

using System;
using System.IO;
using System.IO.Packaging;
using System.Windows.Documents;
using System.Windows.Xps.Packaging;
using System.Windows.Media.Imaging;
using System.Collections.Generic;   
using System.Windows.Forms;

namespace WindowsFormsApplication1
    public partial class Form1 : Form
        public Form1()

        private void button1_Click(object sender, EventArgs e)
                string xpsFile = "c:\\Completed-Form.xps";
            catch (Exception ex)
                MessageBox.Show (ex.Message);

        static public void xpsToBmp(string xpsFile)
            XpsDocument xps = new XpsDocument(xpsFile, System.IO.FileAccess.Read);
            FixedDocumentSequence sequence = xps.GetFixedDocumentSequence();

			for (int pageCount = 0; pageCount < sequence.DocumentPaginator.PageCount; ++pageCount)
                DocumentPage page = sequence.DocumentPaginator.GetPage(pageCount);
                RenderTargetBitmap toBitmap = new RenderTargetBitmap((int)page.Size.Width,(int)page.Size.Height,96,96,System.Windows.Media.PixelFormats.Default);


                BitmapEncoder bmpEncoder = new BmpBitmapEncoder();

                FileStream fStream = new FileStream("c:\\xpstobmp" + pageCount + ".bmp", FileMode.Create, FileAccess.Write);
} (C) 2021    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About