Home : TIFF : Tiff Tags : Split a Multipage TIFF Into Multiple Single Page TIFF Files, Preserving All Tiff Tags
Q10378 - HOWTO: Split a Multipage TIFF Into Multiple Single Page TIFF Files, Preserving All Tiff Tags

Our PdfDocument object has the built in ability to split a multipage PDF into multiple single-page PDF files. This feature isn't built in to our TiffDocument object while keeping the Tiff Tags. However, with a bit of extra work, this can be accomplished quite handily:

/// <summary>

/// Splits the tiff with the name passed in to multiple files

///

/// if in file is c:\someDir\foo.tif and has 3 pages, the result will be

/// c:\someDir\foo_0000.tif

/// c:\someDir\foo_0001.tif

/// c:\someDir\foo_0002.tif

/// </summary>

/// <param name="inFile"></param>

private static void SplitTif(string inFile)

{

// This reads the original TIFF and preserves tags

TiffDocument sourceDoc = new TiffDocument(inFile);

 

// since we're splitting, we will iterate through each page

for (int i = 0; i < sourceDoc.Pages.Count; i++)

{

// This stuff is done out longhand so you can see how we're building the filename

string filePath = Path.GetDirectoryName(inFile);

string fileName = Path.GetFileNameWithoutExtension(inFile);

string fileExt = Path.GetExtension(inFile);

string counter = i.ToString("D4");

string pageFileName = filePath + "\\" + fileName + "_" + counter + fileExt;

 

// This is where the actual work is

// currentPageDoc is going to be loaded with one page (image and all tags)

// then saved out to the new file

TiffDocument currentPageDoc = new TiffDocument();

currentPageDoc.Pages.Add(sourceDoc.Pages[i]);

currentPageDoc.Save(pageFileName);

}

}

Related Articles
No Related Articles Available.

Article Attachments
No Attachments Available.

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
No user comments available for this article.

Powered By InstantKB.NET v1.3
Copyright © 2002, 2017. InstantASP Ltd. All Rights Reserved