How to convert PDF to Images in C# and VB.Net

Convert PDF to Images format in C# and VB.Net



Document .Net can help your application to convert a document from a one format to another.
You'll need only to Load a document and Save to a desired format.


            DocumentCore dc = DocumentCore.Load("...");
            dc.Save("....");

Document .Net supports these formats:

In this code sample, we will show you how to convert PDF (DOCX, RTF, HTML) in Images.
Each document page will be saved in its own image format: PNG, JPEG, TIFF with different DPI.

For example: We have the PDF document with three pages inside:


            // PaginationOptions allow to know, how many pages we have in the document. 
            DocumentPaginator dp = dc.GetPaginator(new PaginatorOptions());

Our task - each document page will be saved in its own image format.

Complete code

using System.IO;
using System;
using SautinSoft.Document;
using SautinSoft.Document.Drawing;
using System.Drawing.Imaging;
using System.Drawing;

namespace Example
{
    class Program
    {
        static void Main(string[] args)
        {
            ConvertPDFtoImages();
        }

        /// <summary>
        /// Convert PDF to Images (file to file).
        /// </summary>
		/// <remarks>
        /// Details: https://sautinsoft.com/products/document/examples/convert-pdf-to-images-in-csharp-vb.php
        /// </remarks>
        static void ConvertPDFtoImages()
        {
            // Path to a document where to extract pictures.
            // By the way: You may specify DOCX, HTML, RTF files also. 
            DocumentCore dc = DocumentCore.Load(@"..\..\example.pdf");
            
            // PaginationOptions allow to know, how many pages we have in the document. 
            DocumentPaginator dp = dc.GetPaginator(new PaginatorOptions());

            // Each document page will be saved in its own image format: PNG, JPEG, TIFF with different DPI.
            dp.Pages[0].Rasterize(800, SautinSoft.Document.Color.White).Save(@"..\..\example.png");
            dp.Pages[1].Rasterize(400, SautinSoft.Document.Color.White).Save(@"..\..\example.jpeg");
            dp.Pages[2].Rasterize(650, SautinSoft.Document.Color.White).Save(@"..\..\example.tiff");

        }
    }
}
    

Download.

        
            
            Imports System.IO
Imports System
Imports SautinSoft.Document
Imports SautinSoft.Document.Drawing
Imports System.Drawing.Imaging
Imports System.Drawing

Namespace Example
    Friend Class Program
        Shared Sub Main(ByVal args() As String)
            ConvertPDFtoImages()
        End Sub

        ''' <summary>
        ''' Convert PDF to Images (file to file).
        ''' </summary>
        ''' <remarks>
        ''' Details: https://sautinsoft.com/products/document/examples/convert-pdf-to-images-in-csharp-vb.php
        ''' </remarks>
        Private Shared Sub ConvertPDFtoImages()
            ' Path to a document where to extract pictures.
            ' By the way: You may specify DOCX, HTML, RTF files also.
            Dim dc As DocumentCore = DocumentCore.Load("..\..\example.pdf")

            ' PaginationOptions allow to know, how many pages we have in the document.
            Dim dp As DocumentPaginator = dc.GetPaginator(New PaginatorOptions())

            ' Each document page will be saved in its own image format: PNG, JPEG, TIFF with different DPI.
            dp.Pages(0).Rasterize(800, SautinSoft.Document.Color.White).Save("..\..\example.png")
            dp.Pages(1).Rasterize(400, SautinSoft.Document.Color.White).Save("..\..\example.jpeg")
            dp.Pages(2).Rasterize(650, SautinSoft.Document.Color.White).Save("..\..\example.tiff")
        End Sub
    End Class
End Namespace

Download.


If you need a new code example or have a question: email us at support@sautinsoft.com or ask at Online Chat (right-bottom corner of this page) or use the Form below:



Questions and suggestions from you are always welcome!

We are developing .Net components since 2002. We know PDF, DOCX, RTF, HTML, XLSX and Images formats. If you need any assistance with creating, modifying or converting documents in various formats, we can help you. We will write any code example for you absolutely free.

© SautinSoft 2002 - 2019