Articles in this section
Category / Section

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

5 mins read

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

Steps to convert a page of the PDF file into a JPG 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 JPG 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.jpg", ImageFormat.Jpeg);

 

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.jpg", ImageFormat.Jpeg)

 

Steps to convert a specific range of pages of the PDF file into JPG 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 JPEG 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()+".jpg", ImageFormat.Jpeg);
 
}

 

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() + ".jpg", ImageFormat.Jpeg)
        Next

 

 

You can download the working sample from PDFToJPEGSample.Zip

By executing the program, you will get the image as follows. PDF to JPEG format

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 the 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 trial message.

 

 

See Also:

https://support.syncfusion.com/kb/article/9455/how-to-convert-pdf-to-jpg-in-wpf-pdfviewer

https://support.syncfusion.com/kb/article/9462/how-to-convert-pdf-to-image-in-wpf-pdfviewer


Conclusion

A new version of Essential Studio® for ASP.NET is available. Versions prior to the release of Essential Studio® 2014, Volume 2 will now be referred to as classic versions. The new ASP.NET suite is powered by Essential Studio for JavaScript, providing client-side rendering of HTML5-JavaScript controls, offering better performance, and better support for touch interactivity. The new version includes all the features of the old version, so migration is easy.

The Classic controls can be used in existing projects; however, if you are starting a new project, we recommend using the latest version of Essential Studio® for ASP.NET. Although Syncfusion® will continue to support all Classic Versions, we are happy to assist you in migrating to the newest edition.

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 forums 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  to leave a comment
Access denied
Access denied