PDFViewer Document

2 posts, 0 answers
  1. Maurício
    Maurício avatar
    42 posts
    Member since:
    Jan 2011

    Posted 07 Mar 2016 Link to this post


    Why this doesn't work?


    It causes the following exception: 

    An unhandled exception of type 'System.NullReferenceException' occurred in Telerik.Windows.Controls.FixedDocumentViewers.dll

    em Telerik.Windows.Controls.FixedDocumentViewerBase.AttachToDocumentEvents(RadFixedDocument document)
    em Telerik.Windows.Controls.FixedDocumentViewerBase.OnDocumentChanged(RadFixedDocument oldValue, RadFixedDocument newValue)
    em Telerik.Windows.Controls.FixedDocumentViewerBase.<.cctor>b__1(DependencyObject s, DependencyPropertyChangedEventArgs e)
    em System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
    em System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
    em System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)


  2. Tanya
    Tanya avatar
    583 posts

    Posted 10 Mar 2016 Link to this post

    Hello Maurício,

    The RadFixedDocument class name is used in both RadPdfViewer and RadPdfProcessing. However, the document models of these controls are still not completely unified and the instances cannot replace each other.

    RadPdfViewer is intended only to visualize PDF documents and the corresponding instance of RadFixedDocument could be created only through PdfFormatProvider as demonstrated in the corresponding help article. When using the constructor of RadFixedDocument, an instance for RadPdfProcessing is created.

    If you would like to create/modify a PDF document and then show it in the viewer, you could first use RadPdfProcessing to apply the desired actions, export the final document and then import it in RadPdfViewer. Here is a modified version of the snippet from your post, which demonstrates how this could be achieved:
    RadFixedDocument document = new RadFixedDocument();
    RadFixedPage page = document.Pages.AddPage();
    FixedContentEditor editor = new FixedContentEditor(page);
    editor.DrawText("Hello world");
    PdfFormatProvider processingProvider = new PdfFormatProvider();
    byte[] content = processingProvider.Export(document);
    PdfFormatProvider viewerProvider = new PdfFormatProvider(new MemoryStream(content), FormatProviderSettings.ReadOnDemand);
    RadFixedDocument viewerDocument = viewerProvider.Import();
    pdfViewer.Document = viewerDocument;

    Hope this is helpful.

    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top