Unsupported Image Format Exception Occurs When Using PdfStreamWriter
Environment
| Version | Product | Author |
|---|---|---|
| 2026.3.810 | RadPdfProcessing | Desislava Yordanova |
Description
When you add an image to a PDF document, PdfProcessing can throw
NotSupportedImageFormatException: 'Not supported image format.'. The exception
usually occurs for one of the following reasons:
- You create
ImageSourcewith an overload that is not available for your target framework. For cross-platform projects, use theImageSource(Stream)constructor. - You export an image format other than JPEG or JPEG2000 without configuring the cross-platform image extensions.
- You pass a
RadFixedDocumenttoPdfStreamWriter. The writer accepts a generatedRadFixedPage, not a complete document.
Solution
Use RadFixedDocument with PdfFormatProvider when you need to create or edit
a complete document. Use PdfStreamWriter when you need to write individual
pages with a low-memory streaming workflow.
Configure Image Processing for Cross-Platform Projects
For cross-platform targets, add the Telerik.Documents.ImageUtils NuGet
package and the platform-specific SkiaSharp.NativeAssets.* package. The
ImageUtils package provides default implementations for
ImagePropertiesResolver and JpegImageConverter. Configure both
implementations before you create or export the image:
Telerik.Documents.ImageUtils.ImagePropertiesResolver defaultImagePropertiesResolver = new Telerik.Documents.ImageUtils.ImagePropertiesResolver();
Telerik.Documents.Extensibility.FixedExtensibilityManager.ImagePropertiesResolver = defaultImagePropertiesResolver;
Telerik.Documents.ImageUtils.JpegImageConverter defaultJpegImageConverter = new Telerik.Documents.ImageUtils.JpegImageConverter();
Telerik.Documents.Extensibility.FixedExtensibilityManager.JpegImageConverter = defaultJpegImageConverter;
Configure the image extensions before export. If both
ImagePropertiesResolverandJpegImageConverterremainnull, export throwsInvalidOperationException.
Create a Complete PDF Document
Use RadFixedDocument and PdfFormatProvider when you need to add multiple
pages, edit document content, or access document-level properties:
RadFixedDocument document = new RadFixedDocument();
RadFixedPage page = document.Pages.AddPage();
using (Stream imageStream = File.OpenRead("path-to-your-image.jpg"))
{
ImageSource imageSource = new ImageSource(imageStream);
page.Content.AddImage(imageSource);
PdfFormatProvider provider = new PdfFormatProvider();
using (Stream output = File.OpenWrite("output.pdf"))
{
provider.Export(document, output, TimeSpan.FromSeconds(10));
}
}
ImageSource(Stream) reads image data from the supplied stream. Keep the stream
open until the image is added and the document is exported.
Write a Page with PdfStreamWriter
Use PdfStreamWriter for a low-memory workflow. Create a RadFixedPage, add the
image to that page, and pass the page to WritePage:
using (Stream imageStream = File.OpenRead("path-to-your-image.jpg"))
{
RadFixedDocument document = new RadFixedDocument();
RadFixedPage page = document.Pages.AddPage();
page.Content.AddImage(new ImageSource(imageStream));
using (Stream output = File.OpenWrite("output.pdf"))
using (PdfStreamWriter writer = new PdfStreamWriter(output))
{
writer.WritePage(page);
}
}
Do not pass RadFixedDocument to WritePage. To write an existing page, pass
its RadFixedPage instance instead.
If the exception continues, verify the following items:
- Confirm that the input stream contains a valid image and that its position is
set to
0before you createImageSource. - Use
ImageSource(Stream)for cross-platform projects instead of aBitmapSourceoverload. - Reference
Telerik.Documents.ImageUtilsand the required native SkiaSharp package when the image format or image quality requires conversion. - Configure
FixedExtensibilityManagerbefore exporting the PDF. - Keep the image stream open until PdfProcessing finishes reading the image.
For package requirements and custom image processing implementations, see Images.