Easily Convert Your PDF to Images in C# | Syncfusion Blogs
Detail-Blog-Page-skeleton-loader-new

Summarize this blog post with:

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.

Transform your PDF files effortlessly in C# with just five lines of code using Syncfusion's comprehensive PDF Library!

Supported frameworks and 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

Getting started with PdfToImageConverter

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.

Convert PDF document to images in ASP.NET Core (Cross-Platforms)

Follow these steps to convert your PDF document into images in an ASP.NET Core app:

  1. First, create a new C# ASP.NET Core web application project.
  2. Install the Syncfusion.PdfToImageConverter.Net NuGet package as a reference to your .NET Standard apps from the NuGet Gallery.

    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.

  1. A default file named HomeController.cs gets added when creating the ASP.NET Core project. Now, include the following namespace in the HomeController.cs file.
    using Syncfusion.PdfToImageConverter;
  1. Let’s add a new button to convert the PDF document to images in the index.cshtml file, as shown below.
    @{Html.BeginForm("ExportToImage", "Home", FormMethod.Post);
        {
            <div>
             <input type="submit" value="Convert Image" style="width:150px;height:27px" />
            </div>
        }
        Html.EndForm();
    }
  1. Add a new action method named ExportToImage in the HomeController.cs file and include the following code example to convert PDF documents to images using the Convert method in the PdfToImageConverter class.
    //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.

Converting a PDF document to image in an ASP.NET Core app
Converting a PDF document to image in an ASP.NET Core app

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.

Say goodbye to tedious PDF tasks and hello to effortless document processing with Syncfusion's PDF Library.

Convert PDF document to images in WPF (Windows-specific)

Follow these steps to convert your PDF document into images in a WPF app:

  1. Create a new WPF app project.
  2. Install the Syncfusion.PdfToImageConverter.WPF NuGet package as a reference to your WPF app from NuGet Gallery.
  3. Include the following namespaces in the MainWindow.xaml.cs file.
    using Syncfusion.PdfToImageConverter;
    using System.Drawing;
    using System.IO;
    using System.Windows;
  1. Add a new button in the MainWindow.xaml file to convert a PDF to images.
    <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>
  1. Add the following code in the btnCreate_Click event to convert a PDF document to images using the Convert method in the PdfToImageConverter class.
    //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.

Join thousands of developers who rely on Syncfusion for their PDF needs. Experience the difference today!

Conclusion

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!

Related blogs

Be the first to get updates

Vikas SVikas S profile icon

Meet the Author

Vikas S

Vikas S is a Product Manager at Syncfusion with specialized skills in File Format products, WinForms, WPF, and Xamarin controls. He began his career at Syncfusion in 2014 as a Software Developer and has since evolved into a technology enthusiast.

Leave a comment