This tutorial shows how to create a C# Windows Console application that uses the RasterCodecs class to merge images into one multipage file.
|Summary||This tutorial covers how to merge images into a multipage file in a C# Windows Console application.|
|Completion Time||30 minutes|
|Visual Studio Project||Download tutorial project (2 KB)|
|Platform||C# Windows Console Application|
|IDE||Visual Studio 2017, 2019|
|Development License||Download LEADTOOLS|
Get familiar with the basic steps of creating a project by reviewing the Add References and Set a License tutorial, before working on the Create a Multipage File from Multiple Images - Console C# tutorial.
Create a new C# Windows Console project, and add the below necessary LEADTOOLS references.
The references needed depend upon the purpose of the project. References can be added by one or the other of the following two methods (but not both). For this project, the following references are needed:
If using NuGet references, this tutorial requires the following NuGet package:
If local DLL references are used, the following DLLs are needed. The DLLs are located at
For a complete list of which Codec DLLs are required for specific formats, refer to File Format Support.
The License unlocks the features needed for the project. It must be set before any toolkit function is called. For details, including tutorials for different platforms, refer to Setting a Runtime License.
There are two types of runtime licenses:
Adding LEADTOOLS NuGet and local references and setting a license are covered in more detail in the Add References and Set a License tutorial.
With the project created, the references added, and the license set, coding can begin.
Program.cs in the Solution Explorer and then add
using Leadtools; and
using Leadtools.Codecs; statements to the using block at the top.
In the Program class add a new method called
MergeFiles(string files, string outputFile).
Create an array of file names to merge. For this tutorial, all CMP files in
"<INSTALL_DIR>\LEADTOOLS21\Resources\Images" will be merged.
// Using block at the top
static void Main(string args)
string files = Directory.GetFiles(@"C:\LEADTOOLS21\Resources\Images\", "*.cmp");
string multipageFile = @"C:\LEADTOOLS21\Resources\Images\merged.tif";
static void MergeFiles(string files, string outputFile)
using (RasterCodecs codecs = new RasterCodecs())
foreach (var file in files)
using (RasterImage image = codecs.Load(file))
codecs.Save(image, outputFile, RasterImageFormat.TifJpeg411, 0, 1, -1, 1, CodecsSavePageMode.Append);
RasterCodecs class implements
IDisposable, make sure it is in a
using statement for proper disposal.
Run the project by pressing F5, or by selecting Debug -> Start Debugging.
If the steps were followed correctly, the application runs and either creates a new file named
merged.tif, or appends pages to that file if it already exists. This file should contain all the images of the CMP files from the LEADTOOLS Images directory.
This tutorial showed how to add the necessary references to save TIFF images as well as how to merge images into a multipage file.