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

PDFViewer Document

1 Answer 152 Views
PDFViewer
This is a migrated thread and some comments may be shown as answers.
Maurício
Top achievements
Rank 1
Maurício asked on 07 Mar 2016, 05:36 PM

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)

 

1 Answer, 1 is accepted

Sort by
0
Tanya
Telerik team
answered on 10 Mar 2016, 02:52 PM
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.
Tags
PDFViewer
Asked by
Maurício
Top achievements
Rank 1
Answers by
Tanya
Telerik team
Share this question
or