The CombineFiles method allows you to combine (append) a list of files from various locations into a single output file, or a serialized sequence of single page output files in a single call. To combine files with different setting per file, see Combining Select Pages Of Each File.

Building the List of Files

The list of files is passed to the CombineFiles method is a simple IList collection of file paths. The path to each file must be a fully qualified path name, relative paths are not accepted.

The files are converted in the order in which they are added to the list. A sample list of files to convert is created below.


IList<String> fileList = new List<String>();


Combining the List of Files

The code sample below uses the file list created above to append all three files into a single multipaged TIFF image. When combining files, the output directory and final output file name must be provided and the directory must exist before the call is made. The code calls CombineFiles to combine all files in the list and place the final output file in the output folder specified.

The combined file will be created using the conversion settings from the profile TIFF 200dpi OptimizedColor. You can change this to use any profile you require.


PNCombineItem resultsItem = null;
String outputDir = @"C:\Test\CombineOutput";
String outputName = "CombinedInput";
resultsItem = 
    PNConverter.CombineFiles(fileList,  // files collection
                             outputDir, // output folder
                             baseName,  // name of combined file
                             false,     // overwrite
                             false,     // create results log 
                             "TIFF 200dpi OptimizedColor", // profile
                             String.Empty, // File-ext
                             String.Empty, // MIME
                             null,         // user settings
                             String.Empty, // not using remote conversion (DCOM)
                             String.Empty, // use default working folder
                             String.Empty  // Log path



The created file, in this case a multipaged TIFF image, will be placed in the specified output folder C:\Test\CombineOutput and named CombinedInput.tif


Reading the Results

When combining a list of files, a PNCombineItem object is returned. This object contains information about the original combine request, the input files used, a list of the output files created and a collection of PNConversionResult objects that lists the results of the conversion for each input file. The results of the conversion can be a list of created files or a collection of error messages detailing why the files were not combined.

This code sample traverses the returns results from the above combine and lists the input files used and the files created.


if (resultsItem != null)
    Console.WriteLine("* Combined ITEM               *");
    Console.WriteLine("BaseName: " + resultsItem.OutputBaseName);
    Console.WriteLine("Directory: " + resultsItem.OutputDirectory);
    Console.WriteLine("Input Files:");
    foreach (String inputFile in resultsItem.InputFiles)
        Console.WriteLine("    " + inputFile);
    Console.WriteLine("Combined Output:");
    if (resultsItem.CombinedOutputFileList.Count == 0)
        Console.WriteLine("    None");
    foreach (String combinedFile in resultsItem.CombinedOutputFileList)
        Console.WriteLine("    " + combinedFile);
    if ( resultsItem.HasErrors() == true)
        foreach (PNConversionResultError errorItem in resultsItem.Errors)
            Console.WriteLine("    Error: " + errorItem.Value);



The console output from the above code is shown below.


Serialized Results

The sample code above used the profile TIFF 200dpi OptimizedColor which created a single, multipaged output file. You can also combine multiple files into a serialized sequence of files. For instance, JPEG images are a single page image format and using the profile JPEG 300dpi Color will create a serialized sequence of files, one JPEG image for each page of each file.