views:

1550

answers:

2

I have a Silverlight 2.0 project that allows a user to add text and images to a canvas. They can move, rotate and resize the text/images. I was wondering the best way to serialize the Silverlight objects to a database and also be able to generate a PDF of the canvas to be printed.

I've read some articles about calling a web-service and passing the serialized data, then saving and generating the PDF. My main question is how to efficiently serialize the Silverlight objects so that they can be re-drawn when a user comes back and if there is a simple way to save the canvas as a PDF or image.

Thanks.

A: 

Unfortunately there isn't a simple way to save a canvas as a pdf or image. We have had a similar problem recently and resorted to having a service running that essentially created an IE browser in memory hosting the silverlight app and then screenshotting it from there. Is all a bit fiddly... I was hoping for something like Canvas.ToImage() ;)

Sorry there isn't a better answer!

I'll find out about serializing shortly.

Cheers,

Dave

David Gouge
Thanks Dave, I was hoping for something simple as well. Let me know what you find out about the serialization.
Austin
+2  A: 

We are experiencing exactly the same problem while building out colaab, a Silverlight 2 collaboration system available at:

http://www.colaab.com

The options seem to be:

  1. Create a server side process to open a web browser and setup the page correctly then take a screenshot of it using software like WebShot.

  2. Send the Xaml from your visual tree to the server (theres a handy class in SilverlightContrib to get the Xaml from the object model). Once you get this on the server side use the fully fledged .NET frameworks WPF support to export this as a PNG. This is not supported on the server side as WPF is a client technology.

  3. Use the HTML Bridge to call the browsers print function

  4. Wait for Silverlight 3 - "better printing and RenderTargetBitmap (AKA bitmap screenshot) are two features that we're planning for the next version."

Thanks,

Bob

-- Bob Thomson storm ideas

http://www.colaab.com http://blog.stormideas.com twitter: movingforwards

stormideas