This is a migrated thread and some comments may be shown as answers.

Printing Pdf Stream with a PdfViewer created on the fly

1 Answer 292 Views
PDFViewer
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Daní
Top achievements
Rank 1
Daní asked on 01 Mar 2012, 06:21 PM
Hi

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?

1 Answer, 1 is accepted

Sort by
0
Kammen
Telerik team
answered on 05 Mar 2012, 05:54 PM

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,

Kammen
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
PDFViewer
Asked by
Daní
Top achievements
Rank 1
Answers by
Kammen
Telerik team
Share this question
or