TL;DR: : Learn how to effortlessly convert PDF pages into images using Syncfusion’s PdfToImageConverter in C#. This guide covers step-by-step instructions for various platforms, including ASP.NET Core, ASP.NET MVC, WinForms, and WPF. Discover how to install the necessary NuGet packages, set up your project, and implement the conversion code to transform PDF files into images efficiently.
Exporting PDF document pages as images can often be a challenging task. To simplify this process, we’ve developed our Syncfusion PdfToImageConverter, which uses PDFium to convert PDF documents into images. PDFium, the same engine used in Google Chrome for rendering PDF files, provides accurate and robust PDF rendering.
In this blog, we’ll guide you through the steps to easily export PDF pages as images across Windows-specific and cross-platforms.
The following table displays the supported frameworks and platforms and the corresponding Syncfusion PdfToImageConverter NuGet packages they support.
| Frameworks | Platforms | Windows-specific / Cross-Platforms | NuGet Package |
| net8.0-windows7.0 / net9.0-windows7.0 / net462 | WinForms | Windows-specific | Syncfusion.PdfToImageConverter.WinForms |
| WPF | Windows-specific | Syncfusion.PdfToImageConverter.WPF | |
| net45 | ASP.NET MVC | Windows-specific | Syncfusion.PdfToImageConverter.AspNet.Mvc5 |
| net8.0 / net9.0 / netstandard2.0 | ASP.NET Core , Blazor | Cross-Platforms | Syncfusion.PdfToImageConverter.Net |
This section explains how to create an application in ASP.NetCore(Cross-Platforms) and WPF (Windows-specific) for converting the PDF to Images.
Note: For more details, refer to PDF to image conversion in C# documentation.
Follow these steps to convert your PDF document into images in an ASP.NET Core app:
Note: If you want to use the PdfToImageConverter in the Linux environment, you need to install the SkiaSharp.NativeAssets.Linux v2.88.6 NuGet package as a reference to your app from NuGet Gallery.
using Syncfusion.PdfToImageConverter;
@{Html.BeginForm("ExportToImage", "Home", FormMethod.Post);
{
<div>
<input type="submit" value="Convert Image" style="width:150px;height:27px" />
</div>
}
Html.EndForm();
} //Initialize the PDF to Image converter.
PdfToImageConverter imageConverter = new PdfToImageConverter();
//Load the PDF document as a stream.
FileStream inputStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.ReadWrite);
imageConverter.Load(inputStream);
//Convert PDF to image.
Stream outputStream = imageConverter.Convert(0, false, false);
MemoryStream stream = outputStream as MemoryStream;
byte[] bytes = stream.ToArray();
using (FileStream output = new FileStream("output.png", FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
output.Write(bytes, 0, bytes. Length);
} After executing the above code examples, we’ll get the following output.
Also, refer to refer to the example on GitHub for converting PDF to images in an ASP.NET Core app.
Similarly, we can use the PdfToImageConverter.Net NuGet to convert a PDF to images in a Blazor app.
Note: The PdfToImageConverter.Net relies on the Pdfium assembly. However, it is not supported in the Blazor WebAssembly due to the framework’s restrictions on accessing assemblies.
Follow these steps to convert your PDF document into images in a WPF app:
using Syncfusion.PdfToImageConverter; using System.Drawing; using System.IO; using System.Windows;
<Grid HorizontalAlignment="Left" Margin="0,0,0,-0.333" Width="793"> <Button Content="Convert PDF to Image" HorizontalAlignment="Left" Margin="318,210,0,0" VerticalAlignment="Top" Width="166" Click=" btnCreate_Click " Height="19"/> <TextBlock HorizontalAlignment="Left" Margin="222,177,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Height="17"/> <TextBlock HorizontalAlignment="Left" Margin="291,175,0,0" TextWrapping="Wrap" Text="Click the button to convert PDF to Image." VerticalAlignment="Top"/> </Grid>
//Initialize the PDF to Image converter.
PdfToImageConverter imageConverter = new PdfToImageConverter();
//Load the PDF document as a stream.
FileStream inputStream = new FileStream("Input.pdf", FileMode.Open,FileAccess.ReadWrite);
imageConverter.Load(inputStream);
//Convert PDF to image.
Stream outputStream = imageConverter.Convert(0, false, false);
Bitmap image = new Bitmap(outputStream);
image. Save("sample.png"); Note: For reference, refer to the example on GitHub for converting a PDF to images in a WPF app.
Thanks for reading! In this blog, we’ve seen how to convert a PDF document to images using the Syncfusion PDFtoImageConverter and C# across in various supported platforms. Try out the steps in this blog and provide your feedback in the comments below!
The existing customers can download the latest version of Essential Studio® from the License and Downloads page. If you are new, try our 30-day free trial to explore our incredible features.
You can also contact us through our support forums, support portal, or feedback portal. We are always happy to assist you!