Converts all image files from directory to single PDF file

Namespace:  SautinSoft
Assembly:  SautinSoft.PdfVision (in SautinSoft.PdfVision.dll) Version: 5.3.6.5

Syntax

      
 C#  Visual Basic 
public int ConvertImageFolderToPDFFile(
	string inputImagesDirectory,
	string outputPdfFile
)
Public Function ConvertImageFolderToPDFFile ( _
	inputImagesDirectory As String, _
	outputPdfFile As String _
) As Integer

Parameters

inputImagesDirectory
String
Full path to directory which contains image files: *.jpg, *.bmp, *.gif, *.tiff, *.tif, *.png, *.ico, *.emf, *.exif, *.jpeg, *.jpe, *.jfif, *.photocd, *.flashpix
outputPdfFile
String
Local path to output PDF file

Return Value

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

Remarks



Examples

CopyHow to convert folder with images to PDF files in C#
using System;
using System.IO;
using System.Collections.Generic;

namespace Sample
{
    class Test
    {

        static void Main(string[] args)
        {
            // Convert folder with images to PDF files.
            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=80; //50-100
            v.ImageStyle.FitImageToPageSize = false;            

            // Specify directory with images. Any local path, like a: "c:\images\".
            string directoryWithImages = Path.GetFullPath(@"..\..\");
            string pdfFile = Path.Combine(directoryWithImages, "Single.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(directoryWithImages, pdfFile);

            // 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 produced PDF in default PDF Reader.
                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(pdfFile) { UseShellExecute = true });
            }
        }
    }
}
CopyHow to convert folder with images to PDF files in VB.Net
Imports System.IO

Namespace Sample
    Friend Class Test

        Shared Sub Main(ByVal args() As String)
            ' Convert folder with images to PDF files
            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 = 80 '50-100
            v.ImageStyle.FitImageToPageSize = False

            ' Specify directory with images. Any local path, like a: "c:\images\".
            Dim directoryWithImages As String = Path.GetFullPath("..\..\")
            Dim pdfFile As String = Path.Combine(directoryWithImages, "Single.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(directoryWithImages, pdfFile)

            ' 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 produced PDF in default PDF Reader.
                System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(pdfFile) With {.UseShellExecute = True})
            End If
        End Sub
    End Class
End Namespace

See Also