New to Telerik Document Processing? Download free 30-day trial

Troubleshooting PdfProcessing

This article provides solutions to common issues that you may observe when working with the PdfProcessing library.

Issue: "InvalidOperationException: 'FixedExtensibilityManager.ImagePropertiesResolver and FixedExtensibilityManager.JpegImageConverter cannot be both null.

You get this error when exporting PDF files containing unsupported images in a .NET Standard environment.

The .NET Standard version of the RadPdfProcessing library has limitations in handling image conversion and quality scaling compared to the .NET Framework version. Unlike the .NET Framework, which includes built-in image processing capabilities, .NET Standard requires manual configuration to process non-JPEG/JPEG2000 images or to adjust image quality. Without the required configurations, attempting to export unsupported images or quality levels will cause an InvalidOperationException.

Solution

In order to successfully export images different than Jpeg and Jpeg2000 and ImageQuality different than High you will need to reference the Telerik.Documents.ImageUtils assembly/NuGet package in your project. The library also exposes the FixedExtensibilityManager class with two specific extensibility points: ImagePropertiesResolver and JpegImageConverter. You would have to set the ImagePropertiesResolver/JpegImageConverter property or create a custom one inheriting the ImagePropertiesResolverBase/JpegImageConverterBase class.

Example 1: Set the default implementation of the ImagePropertiesResolver class

    Telerik.Documents.ImageUtils.ImagePropertiesResolver defaultImagePropertiesResolver = new Telerik.Documents.ImageUtils.ImagePropertiesResolver(); 
    Telerik.Windows.Documents.Extensibility.FixedExtensibilityManager.ImagePropertiesResolver = defaultImagePropertiesResolver; 

Example 2: Set the default implementation of the JpegImageConverter class

   Telerik.Windows.Documents.Extensibility.JpegImageConverterBase defaultJpegImageConverter = new Telerik.Documents.ImageUtils.JpegImageConverter(); 
   Telerik.Windows.Documents.Extensibility.FixedExtensibilityManager.JpegImageConverter = defaultJpegImageConverter; 

Example 3: Create a custom implementation inheriting the JpegImageConverterBase abstract class

    internal class CustomJpegImageConverter : Telerik.Windows.Documents.Extensibility.JpegImageConverterBase 
    { 
        public override bool TryConvertToJpegImageData(byte[] imageData, ImageQuality imageQuality, out byte[] jpegImageData) 
        { 
            IMagickFormatInfo? formatInfo = MagickFormatInfo.Create(imageData); 
            if (formatInfo != null && formatInfo.SupportsReading) 
            { 
                using (MagickImage magickImage = new MagickImage(imageData)) 
                { 
                    magickImage.Alpha(AlphaOption.Remove); 
                    magickImage.Quality = (int)imageQuality; 
 
                    jpegImageData = magickImage.ToByteArray(MagickFormat.Jpeg); 
                } 
 
                return true; 
            } 
 
            jpegImageData = null; 
            return false; 
        } 
    } 

You can read more about the requirements and implementation in the PdfProcessing Cross-Platform Images article.

See Also

In this article