When trying to convert a Word document to PDF through the Telerik Document Processing libraries I got the error message below when I tried to convert a Word document containing a high-res image:
System.InvalidOperationException
HResult=0x80131509
Message=FixedExtensibilityManager.JpegImageConverter cannot be null. The .NET Standard does not define APIs for converting images or scaling their quality. In order to export images different than Jpeg and Jpeg2000 or ImageQuality different than High you will need to reference the Telerik.Documents.ImageUtils assembly/NuGet in your project and to set its basic implementation to the FixedExtensibilityManager.JpegImageConverter property or to create a custom one inheriting the JpegImageConverterBase class. For more information go to: https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/cross-platform
Source=Telerik.Documents.Fixed
StackTrace:
at Telerik.Windows.Documents.Fixed.Model.Resources.EncodedImageData.TryCreateFromUnknownImageDataWithScaledQuality(Byte[] data, ImageQuality imageQuality, EncodedImageData& encodedImageData)
at Telerik.Windows.Documents.Fixed.Model.Resources.ImageSource.DoOnUnknownData(Byte[] unknownData, ImageQuality imageQuality, Action`1 doOnEncodedData)
at Telerik.Windows.Documents.Fixed.Model.Resources.ImageSource.InitializeImageInfoFromUnknownData(Byte[] unknownData, ImageQuality imageQuality)
at Telerik.Windows.Documents.Fixed.Model.Resources.ImageSource.EnsureImageInfo()
at Telerik.Windows.Documents.Fixed.Model.Resources.ImageSource.get_Width()
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.Objects.ImageXObject.CopyPropertiesFrom(IPdfExportContext context, ImageSource imageSource)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.PdfExportContext.GetResource(ImageSource resource)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.PdfContentExportContext.GetResource(ImageSource imageSource)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.ContentElementWriters.ImageWriter.WriteOverride(PdfWriter writer, IPdfContentExportContext context, Image element)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.ContentElementWriters.MarkableContentElementWriter`1.Write(PdfWriter writer, IPdfContentExportContext context, Object element)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.ContentElementWriters.ContentElementWriterBase.WriteElement(PdfWriter writer, IPdfContentExportContext context, Object element)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.ContentElementWriters.ClippingWriter.WriteOverride(PdfWriter writer, IPdfContentExportContext context, Clipping clipping)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.ContentElementWriters.ContentElementWriter`1.Write(PdfWriter writer, IPdfContentExportContext context, Object element)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.ContentElementWriters.ContentElementWriterBase.WriteElement(PdfWriter writer, IPdfContentExportContext context, Object element)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.ContentElementWriters.ContentRootWriter.WriteOverride(PdfWriter writer, IPdfContentExportContext context, IContentRootElement element)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.ContentElementWriters.ContentElementWriter`1.Write(PdfWriter writer, IPdfContentExportContext context, Object element)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.ContentElementWriters.ContentElementWriterBase.WriteElement(PdfWriter writer, IPdfContentExportContext context, Object element)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.DocumentStructure.ContentStream.BuildContentData(IPdfExportContext context, IResourceHolder resourceHolder, IContentRootElement contentRootElement)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.DocumentStructure.Page.CopyPropertiesFrom(IPdfExportContext context, RadFixedPage fixedPage)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.DocumentStructure.DocumentCatalog.CopyRadFixedPageProperties(RadFixedPage source, Page destination, IRadFixedDocumentExportContext context)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.DocumentStructure.DocumentCatalog.CopyPagePropertiesFrom(IRadFixedDocumentExportContext context)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.DocumentStructure.DocumentCatalog.CopyPropertiesFrom(IRadFixedDocumentExportContext context)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.PdfExporter.Export(IRadFixedDocumentExportContext context, Stream output)
at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider.ExportOverride(RadFixedDocument document, Stream output)
at Telerik.Windows.Documents.Common.FormatProviders.FormatProviderBase`1.Export(T document, Stream output)
at Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider.ExportOverride(RadFlowDocument document, Stream output)
at Telerik.Windows.Documents.Common.FormatProviders.FormatProviderBase`1.Export(T document, Stream output)
at DocumentGeneration.API.Features.Conversion.DocumentConverter.Save(RadFlowDocument document, String format)
The error message brought me to the following page explaining why I got this error:
In the .NET Framework version of PdfProcessing, scenarios like reading fonts and converting images or scaling their quality are something that comes out of the box. However, the .NET Standard specification doesn't specify APIs to provide such functionalities built in the library. To get around the limitations in .Net Standard you need to set a FontsProvider
and JpegImageConverter
yourself.
A default implementation of the JpegImageConverter class exists in the Telerik.Documents.ImageUtils assembly. This implementation uses the ImageSharp and TiffLibrary.ImageSharpAdapter libraries to convert images to Jpeg format.
Here is some example code on how to set it: