XPS in Silverlight revisited
Note: the XPS viewer is a proof-of-concept and doesn't provide correct XPS rendering. See Document Toolkit for a fast, feature-rich and 100% client-only XPS viewer that does render properly.
I took a shot at creating a proof-of-concept XPS viewer for Silverlight 2. The viewer is based on the excellent work of David Anson who managed to add XPS support to Silverlight with his SimpleSilverlightXpsViewer.
XPS and Silverlight 2
XPS documents heavily rely on the Glyphs element to display text. Fonts used by Glyphs elements must be embedded as resource in an assembly in Silverlight 2. Creating a general-purpose XPS viewer seems impossible for you cannot have all the fonts in the world compiled into your assembly. Read more on this restriction in this blog post by David Anson.
This XPS viewer uses a workaround where Glyphs elements are replaced by TextBlock elements. This allows for a client-only XPS solution in Silverlight 2. Apart from some side effects, it works surprisingly well.
Go see for yourself!
The source code of the XpsViewer will be published soon, I still have some cleaning up to do.
13 Comments
Fallon Massey said:
I like it, looking forward to the source code.
Laurence Moroney said:
This is *gorgeous* -- nice job!
I'm looking forward to the source so I can put some chapters from my SL2 and (forthcoming) SL3 books online...
NICE JOB!
Dhams said:
I am also make research on the David Anson. Really good stuff !!!
That sample was build on Sliverlight 2 bita version. I am looking for the Sliverlight 2.0 release version.
Can you suggest any changes that should be make to work this sample on Silverlight 2.0 release version ?
I got an error "Error HRESULT E_FAIL has been returned from a call to a COM component."
for the statement : pageContents.Children.Add(xamlCanvas);
And yaah waiting for your source code !!! :)
John Bruin said:
Not working very well for me... It messes up the objects. Has this anything to do with my screen resolution?
Bob Thomson said:
This looks really promising. We've managed to get round the FontUri issue with Glyphs in our Silverlight 2 collaboration application, colaab: http://colaab.com
By compiling the obfuscated font files into a separate Silverlight DLL on the server side using MSBuild and loading that in dynamically.
It's not pretty code, but it works!
Thanks,
Bob
--
Bob Thomson
storm ideas
http://colaab.com http://blog.stormideas.com
twitter: movingforwards
Nathan said:
I have the same experience as John Bruin has. Objects are messed up. For a screendump, see here:
Koen said:
John & Nathan: I made a classic mistake by not using InvariantCulture. Rendering issues should be fixed now
Nathan said:
Hiya Koen,
nice job. Indeed, now it works. Do you think its also possible to save this document to disk (save to xps -> disk) or even een "print" option?
Just wondering... :)
Regards, Nathan
Koen said:
Nathan: a save-as dialog and printing are both features that are not available in Silverlight 2.
Nathan said:
Instead of parsing the xps document (what you do now) you could do a redirect to it prompting the user to save right ?
Koen said:
Nathan: an external link (using window.open or something similar) is possible, but whether a save-as dialog or an inline XPS document is shown depends on http headers send by the server and local installed applications capable of viewing XPS documents.
John Bruin said:
Works great now!
Robert Woltz said:
Looks great looking forward to the release. Us LOB designers need this if we are going to develope deeply in Silverlight.
Thank you for all the hard work, it really looks great. Can't wait for the release.


