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

PdfViewer not showing document

1 Answer 162 Views
PDFViewer
This is a migrated thread and some comments may be shown as answers.
Tony
Top achievements
Rank 1
Tony asked on 18 Sep 2012, 03:12 PM
I have a RadPdfViewer that is being loaded from a stream.  I am experiencing 2 issues with this control that is giving me fits.
1. The first issue is that when I first go to my page with the PdfViewer, the document is always blank.... it never loads. The memory stream is there however.  When I return to this page the second time and on, the Pdf loads most of the time (with the same PDF or a different one) - it seems to be sporadic.

My Xaml:
<telerik:RadPdfViewer x:Name="pdfViewer" telerik:ScrollViewerExtensions.EnableMouseWheel="True"
                                      ScrollViewer.VerticalScrollBarVisibility="Auto"
                                      Mode="Pan"
                                      Background="{StaticResource AppBackgroundBrush}" />

My code behind. This method is called once the stream is loaded into my view model.
public override void AttachmentReady()
{
    Dispatcher.BeginInvoke(() =>
    {
        timer.Tick +=
                delegate(object s, EventArgs args)
                {
                    pdfViewer.DocumentSource = new PdfDocumentSource((DataContext as ViewDocumentViewModel).PdfAttachmentStream);
                    timer.Stop();
                };
 
        timer.Interval = new TimeSpan(0, 0, 0, 0, 300); // if I dont wait, the pdf will never load
        timer.Start();
    });
}


This usually works the second time on... never the first time.
As an aside, if i use the following code as suggested in the forums, i get a null exception in PdfFormatProvider the first time. (Yes, my PdfAttachmentStream has data loaded)
delegate(object s, EventArgs args)
{
    PdfFormatProvider provider = new PdfFormatProvider((DataContext as DocumentViewModelBase).PdfAttachmentStream, FormatProviderSettings.ReadAllAtOnce);
    pdfViewer.Document = provider.Import();
};


2. My second (less important issue) is that I have to use a timer or sleep thread to get any sort of consistency with the document rendering. If i do not delay the thread, the document will never load.

Any thoughts?







1 Answer, 1 is accepted

Sort by
0
Kammen
Telerik team
answered on 19 Sep 2012, 03:48 PM
Hello Tony,

It is really hard for me to understand what you are trying to do without having the full source code. Is it possible to isolate the problem and send us a working demo that we can investigate in a support ticket? This is the best way that we can help you solve the problem. 

Looking forward to your answer.


Kind regards,
Kammen
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

Tags
PDFViewer
Asked by
Tony
Top achievements
Rank 1
Answers by
Kammen
Telerik team
Share this question
or