Using SkiaImageFormatProvider
| Minimum Version | R3 2022 |
|---|---|
| Target Framework | .NET Standard / .NET (Target OS: None) |
Use SkiaImageFormatProvider to export RadFixedPage objects to .png, .jpg, .jpeg, or .webp images through the third-party SkiaSharp library. To export a full PDF document, iterate its pages and save each page as a separate image.
This feature is available for cross-platform
.NET Standardand.NETtargets that useTarget OS: None. For WPF and WinForms-specific alternatives, refer to these articles:
Requirements
To enable the image export functionality in your application, add references to the following packages:
- The
Telerik.Documents.Fixed.FormatProviders.Image.SkiaNuGet package. - The
SkiaSharpNuGet package. - The
SkiaSharp.NativeAssets.*NuGet package. This package may differ depending on the target platform. Versions are available for Windows, macOS, Linux, WebAssembly, Android, iOS, and others.
Set up a FontsProvider implementation so the renderer can read document fonts and draw the image correctly.
Exporting Pages to Images
To convert document pages to images, use the Export() method. SkiaImageFormatProvider exports RadFixedPage objects, not RadFixedDocument objects. Iterate the pages of a PDF document and save each page in a separate file.
Export RadFixedDocument to Image
PdfFormatProvider pdfFormatProvider = new PdfFormatProvider();
RadFixedDocument fixedDocument = pdfFormatProvider.Import(File.ReadAllBytes("Sample.pdf"), TimeSpan.FromSeconds(10));
SkiaImageFormatProvider imageProvider = new SkiaImageFormatProvider();
int count = 1;
foreach (RadFixedPage page in fixedDocument.Pages)
{
byte[] resultImage = imageProvider.Export(page, TimeSpan.FromSeconds(10));
File.WriteAllBytes(@"C:\Temp\Page " + count++ + ".png", resultImage);
}
Exporting Asynchronously
Use ExportAsync() when you want to perform the conversion asynchronously.
Export RadFixedDocument to Image Async
public async void ExportAsync()
{
PdfFormatProvider pdfFormatProvider = new PdfFormatProvider();
RadFixedDocument fixedDocument = pdfFormatProvider.Import(File.ReadAllBytes("Sample.pdf"), TimeSpan.FromSeconds(10));
SkiaImageFormatProvider imageProvider = new SkiaImageFormatProvider();
int count = 0;
await Parallel.ForEachAsync(fixedDocument.Pages, async (page, token) =>
{
int currentCount = Interlocked.Increment(ref count);
byte[]? result = await imageProvider.ExportAsync(page, TimeSpan.FromSeconds(10));
File.WriteAllBytes(@"C:\my_temp\Page" + currentCount + ".png", result);
});
}
Export Settings
The SkiaImageFormatProvider exposes SkiaImageExportSettings so you can control the image format, quality, scaling, and antialiasing.