Edit this page

Exception Handling

RadPdfViewer provides an API for handling exceptions caused by documents which cannot be loaded correctly because of unsupported features of the control. More information about the unsupported features in RadPdfViewer is available here.

How to Handle Exceptions

The DocumentSource property of RadPdfViewer exposes an OnException event. The event handler receives two arguments:

  • The sender argument contains the DocumentSource. This argument is of type object, but can be cast to the Telerik.Windows.Documents.Fixed.PdfDocumentSource type.

  • A Telerik.Windows.Documents.Fixed.Model.OnDocumentExceptionEventArgs object. This argument allows you to access the actual exception thrown by RadPdfViewer.

This is an example how to subscribe the event and handle the exception if there is an unsupported filter:

        private void LoadFromUri(object sender, System.Windows.RoutedEventArgs e)
        {
            this.pdfViewer.DocumentSource = new PdfDocumentSource(new System.Uri("PdfViewerDemo;component/SampleData/Sample.pdf", System.UriKind.Relative));
            this.pdfViewer.DocumentSource.OnException += DocumentSource_OnException;
        }

        private void DocumentSource_OnException(object sender, OnExceptionEventArgs e)
        {
            NotSupportedFilterException filterException = e.Exception as NotSupportedFilterException;
            if (filterException != null)
            {
                // The document contains a filter which is not supported.
            }
        }

The Telerik.Windows.Documents.Fixed.OnExceptionEventArgs has an Exception property which represents the actual exception thrown by RadPdfViewer. All exceptions for features which are not supported by RadPdfViewer inherit from the Telerik.Windows.Documents.Exceptions.NotSupportedFeatureException class:

  • NotSupportedFilterException: represents an exception for a filter which is not supported. This exception has a FilterName property which specifies the name of the filter.

  • NotSupportedEncryptionException - represents an exception for an encryption which is not supported. This exception has e EncryptionCode property which specifies the code of the encryption.

  • NotSupportedFontException – represents an exception for a font which is not supported. This exception has a FontType property which specifies the type of the font.

  • NotSupportedShadingTypeException – represents an exception for a shading type which is not supported. This exception has e ShadingType property which specifies the type of the shading.

  • NotSupportedStreamTypeException – represents an exception for a stream type which is not supported. A stream is not supported if it does not support read or seek. This exception has a SupportSeek and SupportRead properties which specify whether the stream supports them.

  • NotSupportedPredefinedCMapException – represents an exception for a predefined CMap which is not supported by RadPdfViewer. This exception has a CMapName which specifies the name of the predefined CMap.

  • NotSupportedScanDecoderException – this exception is thrown if the document contains a scan decoder which is not supported by RadPdfViewer.

  • NotSupportedXObjectTypeException – this exception is thrown if the document contains a XObject type which is not supported by RadPdfViewer.

Was this article helpful? Yes No

Give article feedback

Tell us how we can improve this article

Dummy