Syncfusion AI Assistant

How can I help you?

Convert PDF file to Image in ASP.NET MVC

25 May 20262 minutes to read

The Syncfusion® PDF to Image converter is a .NET library used to convert PDF document to image in ASP.NET MVC application.

Steps to convert PDF document to Image in ASP.NET MVC

Step 1: Create a new C# ASP.NET Web Application (.NET Framework) project.
Create ASP.NET MVC application

Step 2: In the project configuration windows, name your project and select Create.
Configuration window1
Configuration window2

Step 3: Install Syncfusion.PdfToImageConverter.AspNet.Mvc5 NuGet package as reference to your .NET applications from NuGet.org.

Step 4: Include the following namespaces in the HomeController.cs file.

using Syncfusion.PdfToImageConverter;
using System.Drawing;
using System.IO;

Step 5: Add a new button in the Index.cshtml as shown below.

@{Html.BeginForm("ExportToImage", "Home", FormMethod.Post);
    {
        <div>
            <input type="submit" value="Convert Image" style="width:150px;height:27px" />
        </div>
    }
    Html.EndForm();
 }

Step 6: Add a new action method named ExportToImage in HomeController.cs and include the below code example to convert PDF document to Image using Convert method in PdfToImageConverter class.

//Initialize 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;
return File(stream.ToArray(), System.Net.Mime.MediaTypeNames.Image.Jpeg, "sample.jpeg");

By executing the program, you will get the image as follows.
Convert PDFToImage MVC output