Merge Tiff template files

Hi,
I have multiple template tiff files, which i would like to merge into one multipage tiff.
Can this be done with Aspose.Imaging? and how?

Best regards
Nicolas

@NHolleran

Yes, you can merge multiple TIFF template files into a single multipage TIFF using Aspose.Imaging. Below is a sample code snippet that demonstrates how to achieve this:

using Aspose.Imaging;
using Aspose.Imaging.FileFormats.Tiff;
using Aspose.Imaging.FileFormats.Tiff.Enums;
using System.IO;

class Program
{
    static void Main()
    {
        // Specify the directory containing the TIFF files
        string dir = @"c:\aspose.work\";
        string[] inputFiles = new string[]
        {
            "template1.tif",
            "template2.tif",
            "template3.tif"
        };

        // Create TiffOptions for the output file
        TiffOptions createOptions = new TiffOptions(TiffExpectedFormat.Default);
        createOptions.Compression = TiffCompressions.None;

        // Create an array to hold the frames
        TiffFrame[] frames = new TiffFrame[inputFiles.Length];

        // Load each TIFF file and create a frame from it
        for (int i = 0; i < inputFiles.Length; ++i)
        {
            using (TiffImage input = (TiffImage)Image.Load(dir + inputFiles[i]))
            {
                frames[i] = TiffFrame.CreateFrameFrom(input.Frames[0], createOptions);
            }
        }

        // Create the output TIFF image with the frames
        using (TiffImage output = new TiffImage(frames))
        {
            using (FileStream fileStream = new FileStream(dir + "MergedOutput.tif", FileMode.Create))
            {
                output.Save(fileStream);
            }
        }
    }
}

Explanation:

  1. Input Files: Specify the paths of the TIFF files you want to merge in the inputFiles array.
  2. TiffOptions: Set the options for the output TIFF file, including the compression type.
  3. Loading Frames: Load each TIFF file and create a frame from it.
  4. Creating Output: Finally, create a new TiffImage with the frames and save it to a file.

This code will create a multipage TIFF file named “MergedOutput.tif” containing all the specified template TIFF files as individual pages.

For more detailed information, you can refer to the Aspose documentation on working with multipage image formats.

If you have any further questions or need additional assistance, feel free to ask!

Hi,

Thanks for the quick reply. Do you have this example in Python?

I have already found “TIFF Images Merge with Python | products.aspose.com”.
But im unablet to load “from aspose.imaging.fileformats.tiff.enums import TiffExpectedFormat and
from aspose.imaging.imageoptions import TiffOptions”.

Could you help me with some more simple python code, which takes the tiff files from a folder and merge them all into one multipage tiff .

Hi, @NHolleran
Sure. Please, take a look at

If you have more questions, please let us know.
Best wishes

Hi,

I will take a look at that page.

Could you also please assist by providing some code that addresses my question?

also am i unablet to load imports:
"from aspose.imaging.fileformats.tiff.enums import TiffExpectedFormat
"from aspose.imaging.imageoptions import TiffOptions”

I just get “Import “aspose.imaging.fileformats.tiff” could not be resolved from source”
pip install aspose-imaging-python-net is installed.

Thanks :slight_smile:

Could you tell me the following information:

  • Operation System you use
  • Do you have .NET Core runtime installed? Just send me please the output of command line dotnet --list-runtimes
  • Python version python --version
  • pip information pip3 --version, pip3 list
  • WIndows

  • Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 6.0.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 8.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.NETCore.App 6.0.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.NETCore.App 6.0.33 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.NETCore.App 8.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.NETCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    Microsoft.WindowsDesktop.App 6.0.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    Microsoft.WindowsDesktop.App 6.0.33 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    Microsoft.WindowsDesktop.App 8.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    Microsoft.WindowsDesktop.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

  • Python 3.11.9

  • pip 24.0 from C:\Program Files\Python311\Lib\site-packages\pip (python 3.11)

Thank you, could you please send me the output of
pip3 list

And one more question - do you use PyCharm or any other Python IDE? Or you use only python shell?