Displaying PDFs in Silverlight - silverlight

I want to make a PDF document reader, and the only thing I've found to help me is "Amyuni PDF Suite" that will turn the PDF into XAML and stream that. Are there any other controls for displaying PDFs in Silverlight? Or could I add an IFrame into Silverlight and let the client render it?
Cheers
Nik

Or could I add an IFrame into Silverlight and let the client render it?
Silverlight doesn't really have that capability. You can make your Silverlight control transparent, and have an HTML div block that sits above your Silverlight control, which you could then load a PDF in, but as for displaying a PDF within Silverlight, I think you're out of luck.
Edit:
This question has some info on how to accomplish transparent Silverlight controls, I hope it helps!

If you're ok with buying the pdf converter you can do something like this:
CanvasObject.Children.Add(XamlReader.Load("xaml string from pdf converter"));
And the pdf should be rendered inside your CanvasObject.
I really think you'll get the best result with some type of conversion to XAML. I imagine it can't be that hard to write the converter yourself, I might be wrong though.

Looks like First Floor Software has a solution but it's still in preview.
http://firstfloorsoftware.com/blog/pdf-for-silverlight-preview/
What we are actually trying to do is convert the PDF to SVG, then use something like: http://www.codeplex.com/XamlTune to then go to Xaml

you can use server side conversion of PDF say into set of bitmaps or as mentioned above SVG and return by WCF service to Silverlight client.

Related

Silverlight PDF Viewer

I want to be able to show PDF docs within my Silverlight 4 application. I know there is no native support for this and the only real way to do this is to use a third party control. I’ve looked around and found what looks to be a couple of good options, but they are expensive and somewhat limited. I don’t know much about PDF docs, but it seems that most of these controls are converting PDFs to something else; such as XOD or XPS.
I am considering writing my own PDF Viewer for my needs, but not sure where to start on something like this. What would be the best format to convert PDFs to for Silverlight and WPF? If I could convert to RTF, I could use existing controls to display the document.
I’m assuming since there is such a lack of PDF for Silverlight controls out there that this will not be easy. Any help or guidance is greatly appreciated.
Thanks,
-Scott
You do have one more option besides re-implementing a pdf control.
With a bit of javascript and silverlight's DOM bridge, you can render your PDF in the browser's native pdf plugin and display it in a 'window' over the top of your silverlight application.
This is how many of the 3rd party "web browser" controls for silverlight work as well.

Show pdf inside silverlight application. PDF to XAML

I need to create silverlight application where customer will see some pdf files.
PDF files have to be inside silverlight control and not rendered as images (customer wants to select text)
For this purposes i need some free libriaries or code to convert pdf file to xaml (or just open pdf so i can convert it to xaml).
Which library can read pdf and help me to convert data to xaml?
Can I read somehow pdf file and write custom convertation tool?
I saw iTextSharp. Is this library can read pdf and help me with my issue?
I will be thankfull for any ideas or links.
I make use of the Acrobat Reader plugin to do the displaying for me. It does require a different method depending on whether your application is running inside or outside the browser (I check if the application is running inside the browser and change the means of display accordingly). If running inside the browser, I overlay the application with an IFrame, as I describe in this article: http://www.silverlightshow.net/items/Building-a-Silverlight-Line-Of-Business-Application-Part-6.aspx. Otherwise, I use the WebBrowser control. I have a control which does this all for you in the source code that accompanies my book, which is downloadable from the Apress website here: http://www.apress.com/9781430272076/.
Hope this helps...
Chris

How can i save my XAML content into a File?

I have a problem. I want to save a XAML state into a file, or something like this. I developed a Silverlight version of PowerPoint, and now i want to save my presentation, but i don't know how...i'm using Silverlight 3 beta(if helps)...
I would like to allow users to upload their photos, music and video file somewhere.....where and how can i do this?
Thanks,
Andrei.
Well, that's a toughy. WPF has the Xaml Writer which can send that state out. Silverlight doesn't :(
What you're doing sounds a lot like Mike Harsh's Silverlight 3 sample. His source is available; Maybe that will provide a suitable approach.
I solved the problem by saving data in XML files. When i want to recreate the state of the app i set all the parameters from my XML file.

Can Silverlight do the following?

Can i do the following in a silverlight page/app? (Note: the silverlight app will be embedded on an ASP.NET MVC website page) :-
Display an image from a resource: eg. www.someDomain.com/image.png
Url of the image to display is passed into the control (ie. it's not hardcoded, but .. say .. entered into a textbox via the user, on the page).
Resize the image.
Add layers to the image. A layer could be .. i donno .. some basic text or another image or icon
change the font or font-size of a layer font.
'Save' the modified image to another url, via an HTTP-POST. So if i've resized the image or added some text-layers these are all rendered into a single bitmap (png/jpg/whatever) which is then POST'ed to a url as binary. (ie. multipart/form-data)
Note:
I've asked this question before but that was for Flash (flv/swf). I'm now interested if this can be done in silverlight.
Updated Question
Also, what software is required to create these silverlight apps? VS2008? Expression blend? I know u can use notepad .. but i'm so new to this I would need some WYSIWYG app, I expect.
The Writable Bitmap API Silverlight 3 sounds pretty much what you're after. You can use the standard Silverlight controls such as TextBlock and Image to lay the image and layers out and then use the API to take a "screenshot" of that layout to upload to a server.
Hope this helps.
Yes it can, but it has similar crossdomain restriction as flash. You'll need a crossdomain.xml or clientaccesspolicy.xml in place on the remote servers to allow silverlight to communicate with them. There is an ms article here which gives some more information on the restrictions on using silverlight to talk to other servers.
Once you have the image then you can manipulate it on the client side using the normal .net libraries for such purposes.
So you might load it with
Bitmap bitmap = new Bitmap(<some stream>);
Graphics g = Graphics.FromImage(bitmap);
and then you can play with it in any way you wish.
g.DrawString("Silverlight image",
new Font("times", 32),
SystemBrushes.WindowText, 0, 0);

Another way to display an XPS document using WPF

I would like to ask if there are any other alternatives, aside from DocumentViewer, for displaying an XPS document in a WPF application? A ready-to-use control or class in .NET if possible.
This is because DocumentViewer is a little slow when you are scrolling through the pages.
Thanks!
No, unless there are any third-party controls that I'm unaware of.
Use NiXPS to convert your XPS document to PDF and use any PDF viewer for WPF out there. This way you will get better performance than you do with DocumentViewer.

Resources