Articles in this section
Category / Section

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

7 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 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:

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

https://www.syncfusion.com/blogs/post/pdf-to-image-conversion-is-made-easy-with-wpf-pdf-viewer.aspx

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