PDFViewer Document

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

    Posted 07 Mar Link to this post

    Hello

    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
    Admin
    Tanya avatar
    404 posts

    Posted 10 Mar 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.

    Regards,
    Tanya
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top