How to create an XPS document?

49,976

If you are working in .NET (v2 or later), you can very easily generate a valid XPS document from a WPF visual.

For an example, take a look at this blog post of mine:

http://nixps.blogspot.com/2008/12/wpf-to-pdf.html

In the example I create a WPF visual and convert it as an XPS file, before doing further processing.

If you are not working in .NET, or want more control on the XPS output, then I would advise you to use a library (like the NiXPS SDK) for this. It is a lot easier to code for, and a lot less error prone than writing out the XML constructs yourself (and doing proper resource management, etc...).

Share:
49,976
Sam
Author by

Sam

Always in search for better answers.

Updated on February 24, 2020

Comments

  • Sam
    Sam over 4 years

    I'd like to create an XPS document for storing and printing.

    What is the easiest way to create an XPS document (for example with a simple grid with some data inside) in my program, and to pass it around?

  • Admin
    Admin over 15 years
    Bizarre. But definitely one way you can do it. I wouldn't suggest doing it this way unless you understood the XPS document specifications.
  • Sam
    Sam over 15 years
    Creating a bizarre XML document, compressed into a zip? Not exactly what I had in mind when I wrote 'easiest way' :)
  • Sam
    Sam over 15 years
    The link to your blog does not work, maybe you can copy the code example in your answer instead?
  • Kristof Van Landschoot
    Kristof Van Landschoot over 15 years
    Copy and paste the URL instead of following it, it's just the href that is wrong. It shows perfectly how to create an XPS-file from a WPF visual.
  • mistertodd
    mistertodd over 12 years
    WPF (Windows Presentation Foundation) wasn't released until .NET Framework 3.0 (with Windows Vista)
  • itsho
    itsho about 9 years
    Notice: NiXPS SDK costs money (750€ is the cheapest package at the moment)
  • Patrick D'Souza
    Patrick D'Souza about 9 years
    NiXPS seems dead at the moment. The homepage nixps.com shows a blank page and the last time the news was updated was 2010 (nixps.com/news.php?id=1)
  • Germán Martínez
    Germán Martínez over 3 years
    Is this tutorial still available anywhere? The blog's gone - but I'm quite interested...