Multipage TIFFs are awesome, aren’t them? Well, actually not so much, especially considering the existance of better alternatives such as PDF files. That’s precisely why we published a post some months ago explaining how to merge image files of any kind into a single PDF file in ASP.NET C# using the iTextSharp open-source library: if you need a single generic container to store your TIFFs and you can deal with PDFs, we strongly suggest to look no further than that post.
However, there are some specific scenarios where you cannot use PDFs and/or you need to stick to TIFFs. That happened to me some days ago, when I had to re-factor a web service who was serving TIFF files to an old program that could only handle TIFF files.
Since I couldn’t use the above PDF-container class, I resorted to code the following helper class, which I’m publishing here hoping that it will help other developers who need to do the same.
/// A small helper class to handle TIFF files
public static class TiffHelper
/// Merges multiple TIFF files (including multipage TIFFs) into a single multipage TIFF file.
public static byte MergeTiff(params byte tiffFiles)
byte tiffMerge = null;
using (var msMerge = new MemoryStream())
foreach (var tiffFile in tiffFiles)
using (var ms = new MemoryStream(tiffFile))
//Get the frame dimension list from the image of the file and
using (System.Drawing.Image tiffImage = System.Drawing.Image.FromStream(ms))
//get the globally unique identifier (GUID)
Guid objGuid = tiffImage.FrameDimensionsList;
//create the frame dimension
FrameDimension dim = new FrameDimension(objGuid);
//Gets the total number of frames in the .tiff file
int pageNum = tiffImage.GetFrameCount(dim);
foreach (Guid guid in tiffImage.FrameDimensionsList)
for (int index = 0; index < pageNum; index++)
FrameDimension currentFrame = new FrameDimension(guid);
msMerge.Position = 0;
tiffMerge = msMerge.ToArray();
That’s about it: the comments are quite self-explanatory, hence there’s not much to add here.
In case you find this class useful, don’t forget to give us a like!