Articles in this section
Category / Section

How to export the PDF pages to images in WinForms FileFormat libraries ?

1 min read

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:

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

 

Conclusion

I hope you enjoyed learning about how to export the PDF pages to images in WinForms FileFormat libraries.

You can refer to our WinForms FileFormat libraries to know about its other groundbreaking feature representations and how to quickly get started for configuration specifications. You can also explore our example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied