Introducing PDF Viewer for Silverlight/WPF

by XAML Team | Comments 14

The long-awaited 2012 Q1 with the first official version of RadPdfViewer is already a fact! This is also the first release of the control for WPF, so don’t forget to check it out in the demos if you have missed it: WPF and Silverlight.

A big “Thank You” to all who tried using RadPdfViewer for Silverlight when it was still in a beta stage for providing such a valuable feedback on the control! We have come a long way with your help and hope that you will enjoy the improvements that the first official version brings out.


For the past few months after we first introduced RadPdfViewer as Beta, we have managed to extend the list of supported PDF features in order to be able to show correctly intrinsic PDF files like the ones normally used in LOB applications. The ameliorations include a wider set of image formats and an extensible architecture for plugging in custom filters. The text rendering system was also rethought and improved to ensure the professional look of the document preview. We also managed to implement clipping and support for color spaces, further polishing the way PDF files are shown. Last but not least, if you use the control in Silverlight 5, you will now be able to print your documents faster and with less memory footprint, because the control now utilizes the vector printing of Silverlight 5.

In the 2012 Q1 release an MVVM friendly API is introduced, which will help you integrate RadPdfViewer more easily. Following popular demand, the DocumentSource of RadPdfViewer has been implemented as a DependencyProperty, allowing data-binding to a Stream, a URI where a document can be found, or a string representing such a URI. For example, if Source is the property in your view-model which you wish to bind the content of the viewer to, you can do that as follows:

<telerik:RadPdfViewer x:Name="viewer" DocumentSource="{Binding Source, Converter={StaticResource PdfDocumentSourceValueConverter}}" />

PdfDocumentSourceValueConverter is a static resource declared as:

<fixed:PdfDocumentSourceValueConverter x:Key="PdfDocumentSourceValueConverter" />

The toolbar that RadPdfViewer used in the beta has been implemented as a separate control now in order to allow customizations of the functionality provided to the end user.

Here is an example of how a RadToolBar can be wired with the commands of the PdfViewer:

  <telerik:RadToolBar DataContext="{Binding ElementName=pdfViewer, Path=Commands}">

            …

  </telerik:RadToolBar>

After setting the DataContext of the toolbar, you can proceed to fill in buttons bound to the commands of the viewer like this:

            <controls:RadButton Padding="4" Command="{Binding OpenPdfDocumentCommand}">

                <ToolTipService.ToolTip>

                    <TextBlock Text="Open" />

                </ToolTipService.ToolTip>

                <Image Source="/Telerik.Windows.Controls.FixedDocumentViewers;component/Images/open.png" Stretch="None" />

            </controls:RadButton>

In this way, you will get the same button that the navigation panel of RadPdfViewer had in the beta version. Only that this time, you can customize the tooltip and the icon or even change the command executed. If you would like to preserve the look of the PdfViewer from the Beta, you can open the demos and copy the content from there. Of course, you can implement other kind of UI just as easily.

Now the experience you get with RadPdfViewer for Silverlight will be much closer to the desktop applications you use for viewing PDFs. What is more, you can build applications with similar look and functionality for Silverlight and WPF with minimal effort.

Happy developing! 

About the author

Iva Toteva

Iva Toteva

is a software developer at one of the XAML teams and works closely with clients to assist them in utilizing the RadControls they use for the purposes of their application. The controls in her domain include RadRichTextBox, RadSpreadsheet and RadPdfViewer.

14 Comments

Ben Hayat
The big question is, does the viewer render properly (page by page) if inserted in RADBook? This was a feature that was discussed as integrating PDF viewer into RADEditor of SL and then placing the Editor in the RADBook. Did such integration ever make it?
Thanks!
..Ben
Deepak Shakya
I do not understand the separation of toolbar from the viewer. The look of the buttons could be changed in the beta version by changing the templates. This is really inconvenient when you just want to use the PDFViewer as is. Too much plumbing work needs to be done so relatively simple task. If people do not want to view the toolbar, they can just collapse it in the template.
I think its better to bring the toolbar back as default look just like in beta.
Deepak Shakya
I can't open the demo for PDFViewer. The screen just blanks out grey. I am using Silverlight 5.
Rafał Fagas
That's great news. Do You plan also to handle the embedded fonts properly? Because, from what I've seen the control uses only predefined fonts.
Iva Toteva
Thank you all for the feedback!
@Ben:
Integration with RadBook is considered for implementation in the near future. Once we are done with the development of the required functionality, we will also make sure to prepare a demo.
@Deepak:

We have decided that users will have better control over the look of RadPdfViewer if the toolbar were a separate control. In this way, editing the template of the PDF viewer is not necessary, whereas the XAML of the toolbar can be just copied from our online documentation - http://www.telerik.com/help/silverlight/radpdfviewer-wiring-ui.html.
As for the problem you have encountered, we would appreciate it if you could open a support ticket about the issue and provide some more details.

@ Rafał:
Currently, RadPdfViewer can show the embedded  fonts if they are supported in Silverlight. This is because the default text rendering system of Silverlight is used and it is not possible to utilize other fonts. We are considering some alternative approaches, but the implementation is quite resource-demanding and is still under discussion.

Fredrik
No plans to have this in the tools for WP7?
Iva Toteva
Hi Fredrik,
Thank you for this suggestion. At this point, however, there are no plans to introduce RadPdfViewer for WP7.
Hasan
Does this support rotation of the objects also? Like I wat some text to be displayed diagonally.
Bill Montemer
We have a Telerik license and I am trying to use the RadPDF Viewer in WPF. I tried the RadPDFTutorial (Jesse Liberty) but the control displays only a blank screen. It tries to load the pages but the Document does not render.
Iva Toteva
Hi all,
Thank you for your interest in RadPdfViewer.
To your questions:
@Hasan
You can check if the files you have with rotated text are imported correctly in the online demos: http://demos.telerik.com/silverlight/#PdfViewer/FirstLook 
@Umapathi
We are currently evaluating the user scenarios that may require a PDF Viewer for Windows Store apps, but nothing has been scheduled yet.

@Bill
You can try opening the document in the click-once examples here and if the document is not displayed properly, there may be problems with its content. You can open a support ticket, so that we can investigate the issue and advise you further.
All the best,
Iva
The Telerik Team
Bill
Resolved it with a simple C# string syntax change.
where the tutorial said to set the PDFViewer DocumentSource like this:
var str = App.GetResourceStream(new System.Uri("RadPDFViewerTutorial;component/Samples/Sample.pdf", System.UriKind.Relative)).Stream;
this.xPdfViewer.DocumentSource = new PdfDocumentSource(str);
You need to add an @ before the uri String.
System.Uri(@"RadPDFViewerTutorial;component/Samples/Sample.pdf", System.UriKind.Relative)).Stream;
duh...
services
Definitely imagine that that you said. Your favourite reason seemed to be on the net the simplest thing to have in mind of. I say to you, I definitely get irked even as folks think about concerns that they plainly do not realize about.You controlled to hit the nail upon the highest and outlined out the whole thing with no need side effect ,folks can take a signal. Will likely be back to get more. Thank you
Iva Toteva
Hello,

As Kammen pointed out in the forum thread you have referenced, RadPdfViewer shows a RadFixedDocument. This document is created by importing a PDF file, but can also be created programmatically. Until genuine PDF export is implemented, it will not be correct to add a Save functionality.

The two demos in the forum show how to implement Save if the documents are only created from the import of PDF files. Due to the fact that this covers the most common use of the control and the user cannot edit the document in the viewer, we believe it is sufficient for now and the control does not suffer from its lack. 

All the best,
Iva Toteva
The Telerik Team

Comments

  1.    
      
      
       
  2. (optional, emails won't be shown on public pages)
  3. (optional)
Read more articles by XAML Team - or - read latest articles in Developer Tools