Convert PDF to JPG with high Quality in C# and VB .Net

Convert PDF to JPG with high Quality in C# and VB .Net.


Complete code.

using System;
using System.IO;

namespace Sample
{
    class Sample
    {
        static void Main(string[] args)
        {
            // Convert PDF to JPG with high Quality
            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();

            // This property is necessary only for registered version
            // f.Serial = "XXXXXXXXXXX";
            string pdfFile = @"..\..\simple text.pdf";
            string jpegDir = Path.GetDirectoryName(pdfFile);

            f.OpenPdf(pdfFile);

            if (f.PageCount > 0)
            {
                // Set image properties: Jpeg, 200 dpi
                f.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
                f.ImageOptions.Dpi = 200;

                // Set 95 as JPEG quality
                f.ImageOptions.JpegQuality = 95;

                //Save all PDF pages to image folder, each file will have name Page 1.jpg, Page 2.jpg, Page N.jpg
                for (int page = 1; page <= f.PageCount; page++)
                {
                    string jpegFile = Path.Combine(jpegDir, String.Format("Page {0}.jpg", page));

                    // 0 - converted successfully                
                    // 2 - can't create output file, check the output path
                    // 3 - conversion failed
                    int result = f.ToImage(jpegFile, page);

                    // Show only 1st page
                    if (page == 1 && result == 0)
                        System.Diagnostics.Process.Start(jpegFile);
                }
            }
        }
    }
}

Download.

        
            Imports System.IO
Imports System.Drawing.Imaging
Imports System.Collections.Generic
Imports SautinSoft

Module Sample

    Sub Main()
        ' Convert PDF to JPG with high Quality
        Dim f As New SautinSoft.PdfFocus()

        ' This property is necessary only for registered version
        ' f.Serial = "XXXXXXXXXXX"
        Dim pdfFile As String = "..\simple text.pdf"
        Dim jpegDir As String = Path.GetDirectoryName(pdfFile)

        f.OpenPdf(pdfFile)

        If f.PageCount > 0 Then
            ' Set image properties: Jpeg, 200 dpi
            f.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg
            f.ImageOptions.Dpi = 200

            ' Set 95 as JPEG quality
            f.ImageOptions.JpegQuality = 95

            'Save all PDF pages to image folder, each file will have name Page 1.jpg, Page 2.jpg, Page N.jpg
            For page As Integer = 1 To f.PageCount
                Dim jpegFile As String = Path.Combine(jpegDir, String.Format("Page {0}.jpg", page))

                ' 0 - converted successfully                
                ' 2 - can't create output file, check the output path
                ' 3 - conversion failed
                Dim result As Integer = f.ToImage(jpegFile, page)

                ' Show only 1st page
                If page = 1 AndAlso result = 0 Then
                    System.Diagnostics.Process.Start(jpegFile)
                End If
            Next page
        End If
    End Sub
End Module

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.