Sam Jost

My problem:

I've got a client-server application. Now the server should create a print page (xps document) and deliver it to the client (via wcf).

Creating an xps document in the server service thread does work using DrawingVisual and DrawingContext.

But using DrawText(...) and stuff to layout the printed page is very tedious and error prone, so I'd like to use xaml to layout my printing page, using for example something like this:

static void XamlStreamToXps(Stream srcXamlStream, ParserContext context, string destXpsFile)

{

XpsDocument document = new XpsDocument(destXpsFile, FileAccess.ReadWrite);

XpsPackagingPolicy packagePolicy = new XpsPackagingPolicy(document);

XpsSerializationManager serializationMgr =

new XpsSerializationManager(packagePolicy, false);

object parsedDocObject = (null == context)

XamlReader.Load(srcXamlStream) :

XamlReader.Load(srcXamlStream, context);

serializationMgr.SaveAsXaml(parsedDocObject);

document.Close();

}

This does work on a client, but on a server I can't render xaml because I have no STA thread. Since I am running on service threads I do not have much choice about the threading model I use.

Is it even possible to create xps documents in a system service using xaml/gui elements like grid

Thanks,

Sam



Re: XML Paper Specification (XPS) Creating an xps document from a system service

Jo0815

Hej Sam,


had the same problem with the threading model, and only way to solve this is to create another thread in STA-mode, where you do the rendering then...

just have a look at the links for some examples:

http://msdn2.microsoft.com/en-us/library/aa969772.aspx
http://msdn2.microsoft.com/en-us/library/ms552914.aspx

hope that helps a bit...
-Jo




Re: XML Paper Specification (XPS) Creating an xps document from a system service

Sam Jost

Yes, thanks, that works!

(Well, now of course I got a whole lot of other (multithreading) issues like sharing data between threads, but these are known problems so I'll get past them).