Articles in this section
Category / Section

How to convert PDF to PNG using C# and VB.NET?

5 mins read

Syncfusion Essential PDF is a .NET PDF Libraries used to create, read, and edit PDF documents. Using Pdf Viewer library, you can convert PDF to PNG in C# and VB.NET. 

Steps to convert a page of the PDF file into a PNG image programmatically:

  1. Create a new C# console application project. Create new console application
  2. Install the Syncfusion.PdfViewer.Windows NuGet package as a reference to your .NET Framework application from NuGet.org. Install NuGet packages
  3. Include the following namespace in the Program.cs file.

C#

using Syncfusion.Pdf.Parsing;
using Syncfusion.Windows.Forms.PdfViewer;
using System.Drawing;
using System.Drawing.Imaging;

 

VB.NET

Imports Syncfusion.Pdf.Parsing
Imports Syncfusion.Windows.Forms.PdfViewer
Imports System.Drawing
Imports System.Drawing.Imaging

 

  1. Use the following code snippet to convert a page of the PDF file to a PNG image.

C#

//Initialize the PdfViewer Control
PdfViewerControl pdfViewer = new PdfViewerControl();
 
//Load the input PDF file
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("../../Data/Barcode.pdf");
 
pdfViewer.Load(loadedDocument);
 
//Export the particular PDF page as image at the page index of 0
Bitmap image = pdfViewer.ExportAsImage(0);
 
// Save the image.
image.Save("Sample.png", ImageFormat. Png);

 

VB.NET

'Initialize the PdfViewer Control
Dim pdfViewer As PdfViewerControl = New PdfViewerControl()
 
'Load the input PDF file
Dim loadedDocument As PdfLoadedDocument = New 
PdfLoadedDocument("../../Data/Barcode.pdf")
 
pdfViewer.Load(loadedDocument)
 
'Export the particular PDF page as image at the page index of 0
Dim image As Bitmap = pdfViewer.ExportAsImage(0)
 
'Save the image.
image.Save("Sample. png ", ImageFormat. Png)

 

Steps to convert a specific range of pages of the PDF file into PNG images programmatically:

  1. Include the following namespace in the Program.cs file.

C#

using Syncfusion.Pdf.Parsing;
using Syncfusion.Windows.Forms.PdfViewer;
using System.Drawing;
using System.Drawing.Imaging;

 

VB.NET

Imports Syncfusion.Pdf.Parsing
Imports Syncfusion.Windows.Forms.PdfViewer
Imports System.Drawing
Imports System.Drawing.Imaging

 

  1. Use the following code snippet to convert the specific range of pages of a PDF file that can be exported as PNG images.

C#

//Initialize the PdfViewer Control
PdfViewerControl pdfViewer = new PdfViewerControl();
 
//Load the input PDF file
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("../../Data/Barcode.pdf");
 
pdfViewer.Load(loadedDocument);
 
//Export all the pages as images at the specific page range
Bitmap[] image = pdfViewer.ExportAsImage(0, loadedDocument.Pages.Count - 1);
 
for (int i = 0; i < image.Length; i++)
{
     // Save the image.
    image[i].Save("Sample" + i.ToString()+".png", ImageFormat. Png);
 
}

 

VB.NET

'Initialize the PdfViewer Control
Dim pdfViewer As PdfViewerControl = New PdfViewerControl()
'Load the input PDF file
Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("../../Data/Barcode.pdf")
 
pdfViewer.Load(loadedDocument)
'Export all the pages as images at the specific page range
Dim image As Bitmap() = pdfViewer.ExportAsImage(0, loadedDocument.Pages.Count - 1)
        For i As Integer = 0 To image.Length - 1
            'Save the image.
            image(i).Save("Sample" + i.ToString() + ".png", ImageFormat.Png)
        Next

 

 

You can download the working sample from PDFToPNGSample.Zip

By executing the program, you will get the image as follows. Output image screenshot

Take a moment to peruse the documentation, where you can find other features like converting Word to PDF, Excel to PDF, XPS to PDF, and HTML to PDF with code examples.

Refer here to explore the rich set of Syncfusion Essential PDF features.

Note:

Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering the Syncfusion license key in your application to use the components without a trail message.

 

 

See Also:


Conclusion

I hope you enjoyed learning about how toconvert PDF to PNG using C# and VB.NET.

You can refer to our .NET PDF Libraries to know about its other groundbreaking feature representations. You can also explore our documentation 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