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

RadFixedDocument Null Reference

3 Answers 142 Views
PDFViewer
This is a migrated thread and some comments may be shown as answers.
Grant
Top achievements
Rank 1
Grant asked on 24 Feb 2015, 05:25 AM
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?

3 Answers, 1 is accepted

Sort by
0
Deyan
Telerik team
answered on 24 Feb 2015, 03:29 PM
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.

 
0
Grant
Top achievements
Rank 1
answered on 24 Feb 2015, 04:34 PM
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
0
Deyan
Telerik team
answered on 26 Feb 2015, 09:34 AM
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.

 
Tags
PDFViewer
Asked by
Grant
Top achievements
Rank 1
Answers by
Deyan
Telerik team
Grant
Top achievements
Rank 1
Share this question
or