)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to export the PDF pages to images in ASP.NET(classic)?

Platform: WinForms |
Control: PDF |
Published Date: February 4, 2015 |
Last Revised Date: March 27, 2020

How to export the PDF pages to images in ASP.NET (classic)?

At present, there is no support to export PDF pages as images in ASP.NET (Classic). However, you can export the PDF Document pages as images by using ExportAsImage functionality available with PdfViewer.Windows as in the below code snippets.

ASPX

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<table width="100%" style="color: #5D6B03" border="1px">
<tr style="width: 100%; background-color: #8EA718; text-align:center">
<td >
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="ExportAsImage" />
</td>
</tr>
</table>
</asp:Content>

Default.aspx.cs 

C#

protected void Button1_Click(object sender, EventArgs e)
{
if (System.IO.Path.GetExtension(FileUpload1.PostedFile.FileName).Equals(".pdf"))
{
//locate the file path and the path the images to be saved
string imagePath = Server.MapPath("~/Images/");
//Clear the previous pdf file images from the Images folder
CleareFolder(imagePath);
//Get the pdf file stream
Stream pdfStream = FileUpload1.PostedFile.InputStream;
//Create an instance of PdfViewerControl
PdfViewerControl pdfViewercontrol = new PdfViewerControl();
//Load the document in the viewer
pdfViewercontrol.Load(pdfStream);
//Export the pages of the loaded document as bitmap images
System.Drawing.Bitmap[] images = pdfViewercontrol.ExportAsImage(0, pdfViewercontrol.PageCount - 1);
int page = 0;
//Save the images in the imagepath defined earlier
foreach (System.Drawing.Bitmap bmp in images)
{
images[page].Save(imagePath + "exportedPage_" + page.ToString() + ".png", System.Drawing.Imaging.ImageFormat.Png);
page++;
}
}
}
/// <summary>
///Clear the Folder.
/// </summary>
/// <param name="folderName"></param>
///<return></return>
private void ClearFolder(string folderName)
{
DirectoryInfo directoryInfo = new DirectoryInfo(folderName);
foreach (FileInfo fileInfo in directoryInfo.GetFiles())
{
fileInfo.IsReadOnly = false;
fileInfo.Delete();
}
}

Sample:

http://www.syncfusion.com/downloads/support/directtrac/general/ze/PdfViewerWeb1755372995

 

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon