Convert folder with images to PDF file in C# and VB.Net

Convert folder with images to PDF file
in C# and VB.Net.


Complete code

using System;
using System.IO;
using System.Collections.Generic;

namespace Sample
{
    class Test
    {
        static void Main(string[] args)
        {
            // Convert a folder with images to PDF file.
            SautinSoft.PdfVision v = new SautinSoft.PdfVision();

            //v.Serial = "XXXXXXXXXXXXXXX";

            // Set some options.
            v.PageStyle.PageSize.Auto();
            //v.PageStyle.PageMarginLeft.Inch(1);
            //v.ImageStyle.Heightmm(150);
            //v.ImageStyle.WidthInch(10);

            v.ImageStyle.JPEGQuality = 95; // 50 - 100
            v.ImageStyle.FitImageToPageSize = false;

            // Specify directory with images. Any local path, like a: "c:\images\".
            string inpFolder = Path.GetFullPath(@"..\..\");
            FileInfo outFile = new FileInfo(@"Result.pdf");

            // Convert all image files from directory to PDF file.
            // Image files: *.jpg, *.bmp, *.gif, *.tiff, *.tif, *.png, *.ico, *.emf, *.exif, *.jpeg, *.jpe, *.jfif, *.photocd, *.flashpix.
            int ret = v.ConvertImageFolderToPDFFile(inpFolder, outFile.FullName);

            // 0 - converting successfully
            // 1 - directory doesn't contain any image file
            // 2 - can't create output file, check the output path
            // 3 - converting failed

            if (ret == 0)
            {
                // Open the resulting PDF document in a default PDF Viewer.
                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile.FullName) { UseShellExecute = true });
            }
        }
    }
}

Download.

        
            Imports System
Imports System.IO
Imports System.Collections.Generic

Namespace Sample
    Friend Class Test
        Shared Sub Main(ByVal args() As String)
            ' Convert a folder with images to PDF file.
            Dim v As New SautinSoft.PdfVision()

            'v.Serial = "XXXXXXXXXXXXXXX"

            ' Set some options.
            v.PageStyle.PageSize.Auto()
            'v.PageStyle.PageMarginLeft.Inch(1);
            'v.ImageStyle.Heightmm(150);
            'v.ImageStyle.WidthInch(10);

            v.ImageStyle.JPEGQuality = 95 ' 50 - 100
            v.ImageStyle.FitImageToPageSize = False

            ' Specify directory with images. Any local path, like a: "c:\images\".
            Dim inpFolder As String = Path.GetFullPath("..\..\")
            Dim outFile As New FileInfo("Result.pdf")

            ' Convert all image files from directory to PDF file.
            ' Image files: *.jpg, *.bmp, *.gif, *.tiff, *.tif, *.png, *.ico, *.emf, *.exif, *.jpeg, *.jpe, *.jfif, *.photocd, *.flashpix.
            Dim ret As Integer = v.ConvertImageFolderToPDFFile(inpFolder, outFile.FullName)

            ' 0 - converting successfully
            ' 1 - directory doesn't contain any image file
            ' 2 - can't create output file, check the output path
            ' 3 - converting failed

            If ret = 0 Then
                ' Open the resulting PDF document in a default PDF Viewer.
                System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFile.FullName) With {.UseShellExecute = True})
            End If
        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.