Convert PDF file to Image in ASP.NET MVC
14 Jul 20262 minutes to read
The Syncfusion® PDF to Image converter is a .NET library used to convert a PDF document to an 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 and select the MVC template.

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

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. Ensure the Input.pdf file is available in the application’s working directory before running the conversion.
//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.
