This project has moved and is read-only. For the latest updates, please go here.

Single and Multipage TIFFs to SINGLE PDF

Feb 4, 2015 at 10:31 PM
I am wanting to combine a directory that may contain single or multi-page TIFFs. I want to combine all of these into a single PDF using Magick.NET

I see how I can do it with single page PDFs by creating a magick image, read and append each page. But what about Multi-Page TIFFs ? Is it as simple as appending each TIFF, or would you have to iterate through each page in the TIFF?

Any thoughts?
Feb 5, 2015 at 7:56 PM
Edited Feb 5, 2015 at 8:15 PM
If you want to read a multi-page tiff you should create a MagickImageCollection instead and just write it to a PDF file.
using (MagickImageCollection pages = new MagickImageCollection("input.tiff"))
{
  pages.Write("output.pdf");
}
Feb 5, 2015 at 8:03 PM
Edited Feb 5, 2015 at 8:03 PM
OK cool, so if I had multiple multi-page tiffs...

I could read them into multiple MagickImageCollections, combine the collections, and then write the single result PDF out?
Feb 5, 2015 at 8:09 PM
Edited Feb 5, 2015 at 8:15 PM
Yup, you could do something like this:
using (MagickImageCollection output = new MagickImageCollection())
{
  foreach (string fileName in Directory.GetFiles(@"C:\InputFolder", "*.tiff"))
  {
    using (MagickImageCollection pages = new MagickImageCollection(fileName))
    {
      output.AddRange(pages);
    }
  }
  output.Write("output.pdf");
}
Feb 5, 2015 at 8:39 PM
Oh wow, thanks dude. Very cool to get answers like this on here.