RadFixedDocument Null Reference

4 posts, 0 answers
  1. Grant
    Grant avatar
    13 posts
    Member since:
    Oct 2011

    Posted 23 Feb 2015 Link to this post

    Hi, 
    I'm setting a RadFixedDocument hat was created using a RadFixedDocumentEditor as the PdfViewer.Document object and see following Null Reference exception:

       at Telerik.Windows.Controls.FixedDocumentViewerBase.AttachToDocumentEvents(RadFixedDocument document)
       at Telerik.Windows.Controls.FixedDocumentViewerBase.OnDocumentChanged(RadFixedDocument oldValue, RadFixedDocument newValue)
       at Telerik.Windows.Controls.FixedDocumentViewerBase.<.cctor>b__1(DependencyObject s, DependencyPropertyChangedEventArgs e)
       at Telerik.Windows.PropertyMetadata.PropertyChangeHook.OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
       at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)
       at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
       at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet, Boolean isBindingInStyleSetter)
       at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
       at Telerik.Windows.Controls.FixedDocumentViewerBase.set_Document(RadFixedDocument value)

    Any ideas?
  2. Deyan
    Admin
    Deyan avatar
    135 posts

    Posted 24 Feb 2015 Link to this post

    Hello Grant,

    Thank you for contacting us.

    As explained in this forum post the current versions of RadPdfViewer and RadPdfProcessing share the same public API, but differ internally. The exception you have reached is caused by these internal model differences.

    When you need to import or export documents with RadPdfProcessing you should use the PdfFormatProvider's constructor that does not require any parameters. You can find more information about this constructor in this RadPdfProcessing formats and conversion documentation article.

    When you need to view some PDF document in RadPdfViewer you should use the constructor that requires two parameters. More information about this PdfFormatProvider's constructor you may find in this RadPdfViewer showing a file documentation article.

    As a result in order to generate document with RadPdfProcessing and then display it in RadPdfViewer you should first export the generated document to stream and then import it in the viewer. The following code snippet shows how to generate sample document with RadFixedDocumentEditor and then show the file with RadPdfViewer:
    RadFixedDocument document = new RadFixedDocument();
     
    using (RadFixedDocumentEditor editor = new RadFixedDocumentEditor(document))
    {
        editor.InsertLine("Some sample RadPdfProcessing document content.");
    }
     
    PdfFormatProvider pdfProcessingProvider = new PdfFormatProvider();
    MemoryStream stream = new MemoryStream(pdfProcessingProvider.Export(document));
    PdfFormatProvider pdfViewerProvider = new PdfFormatProvider(stream, FormatProviderSettings.ReadOnDemand);
    this.pdfViewer.Document = pdfViewerProvider.Import();


    I hope this is helpful. If you have any other questions or concerns please do not hesitate to contact us again.

    Regards,
    Deyan
    the Telerik team
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. DevCraft banner
  4. Grant
    Grant avatar
    13 posts
    Member since:
    Oct 2011

    Posted 24 Feb 2015 in reply to Deyan Link to this post

    Thanks Deyan--that really helps and fixes the null reference. It's a shame the namespace is the same here...

    With that change I'm still not seeing the pdf rendered--I see a blank page.

    I've attached the pdf that is outputted and that I'm using as the stream (rename it to pdf).

    Grant
  5. Deyan
    Admin
    Deyan avatar
    135 posts

    Posted 26 Feb 2015 Link to this post

    Hello Grant,

    I am attaching a sample project that basically generates a PDF similar to the one you have sent and displays it directly in RadPdfViewer using the code I have previously sent to you. Testing with the latest version of the product the demo project displays the generated file correctly.

    I hope this helps. If you still experience any issues do not hesitate to contact us again.

    Regards,
    Deyan
    the Telerik team
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top