Printing Pdf Stream with a PdfViewer created on the fly

2 posts, 0 answers
  1. Daní
    Daní avatar
    303 posts
    Member since:
    Feb 2008

    Posted 01 Mar 2012 Link to this post


    I want to print a pdf stream. To achieve this, I download the stream from server (via a WCF service that generates the pdf on the fly) then, I create a RadPdfViewer on the fly, set the DocumentSource to a PdfDocumentSource with the downloaded stream and when the PdfDocumentSource loaded event is raised I call the Print method on the PdfViewer. The result is that nothing happens. Setting a breakpoint on the PdfDocumentSource.Loaded event I can see that PdfViewer.DocumentSource property is notifying an UnauthorizedAccesException.

    Any help?
  2. Kammen
    Kammen avatar
    312 posts

    Posted 05 Mar 2012 Link to this post

    Hello Dani,

    As you may know, printing in Silverlight has to be user initiated. It is not possible to print something after some time has passed since the user interaction.
    Therefore, the work that needs to be done in order to load the document must be outside that user initiated action. Here are some steps that will help you to achieve such functionality:

    1. You should create RadFixedDocument from the stream. This code does the trick:

    Stream s = App.GetResourceStream(new Uri("/FixedDocumentViewerDemo;component/Sample.pdf", UriKind.Relative)).Stream;
    PdfDocumentSource source = new PdfDocumentSource(s);
    source.Loaded += (se, e) => { this.document = source.Document; };

     This code should be executed before the click occurs.

    2. When you have the document in the field this.document, you can set it to the viewer's Document property and call the Print() method. 

    We will work further to find a better way to achieve such functionality, however for now this is the way you can do this.

    All the best,

    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. DevCraft banner
Back to Top