Tutorial: Split a Multipage Image File Into Separate Files

In a previous post, we shared a tutorial on how to create a multipage file from multiple images. However, sometimes developers are looking to split a multipage file into separate files instead. In an office workspace, there is always something that needs to be printed and signed. Whether it’s for approving an idea, or for legal purposes, these documents are usually more than one page long. The signer will not want to print out every page of the document just to sign one page, that would only be a waste of time and paper. Splitting the document up will give you the one page that needs to be signed. Splitting files apart can easily be done when using the RasterCodecs Save Method within the LEADTOOLS Imaging libraries.

All that needs to be done to split a multipage file is first, get the total number of pages, and second, loop through each page and save it to one of many LEADTOOLS supported file formats. The code below will show you the core code on how to make the split. Or refer to our complete step-by-step tutorial on how to Split a Multipage Image File Into Separate Files.


// Split a Multipage Image into Single Files
using (RasterCodecs codecs = new RasterCodecs())
{
	int totalPages = codecs.GetTotalPages(inputFile);
	for (int page = 1; page <= totalPages; page++)
	{
		string outputFile = $@"C:\Users\Public\Documents\LEADTOOLS Images\
		{System.IO.Path.GetFileNameWithoutExtension(inputFile)}_page{page}.png";
		using (RasterImage image = codecs.Load(inputFile, page))
			codecs.Save(image, outputFile, RasterImageFormat.Png, 0);
	}
}

Try it out!

To test this for yourself, make sure to get the latest LEADTOOLS SDK code for free straight from our site if you have not already. This trial is good for 60 days and comes with unlimited chat and email support.

Support

Need help getting this sample up and going? Contact our support team for free technical support! For pricing or licensing questions, you can contact our sales team (sales@leadtools.com) or call us at 704-332-5532.


Stay tuned because, as promised in our previous post, we’ll be featuring a lot more tutorials that programmers can use to develop applications that will directly impact data capture, recognition, exchange, and other pressing business needs.

About 

Technical Marketing Engineer

This entry was posted in General Imaging. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *