Click or drag to resize

PdfFocusToImage(String, String) Method

Saves all pages of PDF document as image files.

Namespace: SautinSoft
Assembly: SautinSoft.PdfFocus (in SautinSoft.PdfFocus.dll) Version: 2024.3.28
Syntax
public int ToImage(
	string outFolder,
	string templateFileName
)

Parameters

outFolder  String
Full path to existing folder where to save images
templateFileName  String
Template file name for image files

Return Value

Int32
0 - saving successfully
2 - can't create output file, check the output path
3 - saving failed, email to support@sautinsoft.com
Remarks
Before converting you may set various image properties using the property ImageOptions. For example, set:
  • Dpi - image resolution in dots per inch. Default value: 200
  • ImageFormat - format for produced images as standard ImageFormat. Default value: Png
  • ColorDepth - color depth or bit depth is the number of bits used to represent the color of a single pixel. Default value: 24 bit RGB
Example
Convert PDF files to 300-dpi Jpeg files in C#
using System;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;

namespace Sample
{
    class Sample
    {
        static void Main(string[] args)
        {
                                  // Get your free 30-day key here:   
             // https://sautinsoft.com/start-for-free/

            //Convert PDF files to 300-dpi JPG files
            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();

            string[] pdfFiles = Directory.GetFiles(@"..\..\..\", "*.pdf");
            string folderWithJPGs = new DirectoryInfo(Directory.GetCurrentDirectory()).CreateSubdirectory("Result").FullName;

            foreach (string pdffile in pdfFiles)
            {
                f.OpenPdf(pdffile);

                if (f.PageCount > 0)
                {
                    //Set image format: Jpeg, 300 dpi
                    f.ImageOptions.Dpi = 300;
                    f.ImageOptions.ImageFormat = SautinSoft.PdfFocus.CImageOptions.ImageFormats.Jpeg;

                    //Save all pages to jpeg files with 300 dpi
                    f.ToImage(folderWithJPGs, Path.GetFileNameWithoutExtension(pdffile));
                }
                f.ClosePdf();
            }
            //Show folder with jpegs
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(folderWithJPGs) { UseShellExecute = true });
        }
    }
}
Convert PDF files to 300-dpi JPG files in VB.Net
Imports System
Imports System.IO
Imports System.Drawing
Imports System.Drawing.Imaging

Namespace Sample
    Friend Class Sample
        Shared Sub Main(ByVal args() As String)
                                  ' Get your free 30-day key here:   
             ' https://sautinsoft.com/start-for-free/

            'Convert PDF files to 300-dpi JPG files
            Dim f As New SautinSoft.PdfFocus()

            Dim pdfFiles() As String = Directory.GetFiles("..\..\..\", "*.pdf")
            Dim folderWithJPGs As String = (New DirectoryInfo(Directory.GetCurrentDirectory())).CreateSubdirectory("Result").FullName

            For Each pdffile As String In pdfFiles
                f.OpenPdf(pdffile)

                If f.PageCount > 0 Then
                    'Set image format: Jpeg, 300 dpi
                    f.ImageOptions.Dpi = 300
                    f.ImageOptions.ImageFormat = SautinSoft.PdfFocus.CImageOptions.ImageFormats.Jpeg

                    'Save all pages to jpeg files with 300 dpi
                    f.ToImage(folderWithJPGs, Path.GetFileNameWithoutExtension(pdffile))
                End If
                f.ClosePdf()
            Next pdffile
            'Show folder with jpegs
            System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(folderWithJPGs) With {.UseShellExecute = True})
        End Sub
    End Class
End Namespace
See Also