PdfViewer not showing document

2 posts, 0 answers
  1. Tony
    Tony avatar
    24 posts
    Member since:
    Nov 2011

    Posted 18 Sep 2012 Link to this post

    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"
                                          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.Interval = new TimeSpan(0, 0, 0, 0, 300); // if I dont wait, the pdf will never load

    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?

  2. Kammen
    Kammen avatar
    313 posts

    Posted 19 Sep 2012 Link to this post

    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,
    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.

Back to Top