Take the following steps to start a project:
In the "Solution Explorer" window, right-click on the "References" folder, and select "Add Reference…" from the context menu. In the "Add Reference" dialog box, select the ".NET" tab, browse to the "C:\LEADTOOLS 19\Bin\DotNet\Win32" folder, and select the following DLLs:
Click the Select button and then press the OK button to add the above DLLs to the application.
| Text | Name |
|---|---|
| Split TIFF | buttonSplit |
Switch to Form1 code view (right-click Form1 in the solution explorer then select View Code) and add the following lines at the beginning of the file:
Imports System.IOImports LeadtoolsImports Leadtools.CodecsImports Leadtools.ImageProcessing
using System.IO;using Leadtools;using Leadtools.Codecs;using Leadtools.ImageProcessing;
Add an event handler to the buttonSplit Click event and code it as follows:
Private Sub buttonSplit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonSplit.Click' Intitialize a new RasterCodecs object.Dim codecs As New RasterCodecs()Dim multiPageFileName As String = CreateMultiPageFile(codecs)' Find out how many pages the file hasDim info As CodecsImageInfo = codecs.GetInformation(multiPageFileName, True)' Loop through the pages of the file; perform specific processing on it, then save each page to a separate file:Dim flip As New FlipCommand()Dim outputDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"For pageNumber As Integer = 1 To info.TotalPages' Load the next image in the loopDim image As RasterImage = codecs.Load(multiPageFileName, 0, CodecsLoadByteOrder.BgrOrGray, pageNumber, pageNumber)' Perform specific processing on the page, such as flipping itflip.Run(image)' Save the page to a separate fileDim pageFileName As String = Path.Combine(outputDir, "Page" + pageNumber.ToString() + ".tif")codecs.Save(image, pageFileName, RasterImageFormat.Tif, 0)NextEnd Sub
private void buttonSplit_Click(object sender, System.EventArgs e){// Intitialize a new RasterCodecs object.RasterCodecs codecs = new RasterCodecs();string multiPageFileName = CreateMultiPageFile(codecs);// Find out how many pages the file hasCodecsImageInfo info = codecs.GetInformation(multiPageFileName, true);// Loop through the pages of the file; perform specific processing on it, then save each page to a separate file:FlipCommand flip = new FlipCommand();string outputDir = @"C:\Users\Public\Documents\LEADTOOLS Images";for(int pageNumber = 1; pageNumber <= info.TotalPages; pageNumber++){// Load the next image in the loopRasterImage image = codecs.Load(multiPageFileName, 0, CodecsLoadByteOrder.BgrOrGray, pageNumber, pageNumber);// Perform specific processing on the page, such as flipping itflip.Run(image);// Save the page to a separate filestring pageFileName = Path.Combine(outputDir, "Page" + pageNumber + ".tif");codecs.Save(image, pageFileName, RasterImageFormat.Tif, 0);image.Dispose();}}
Add the following code to the Form1 class:
Function CreateMultiPageFile(ByVal codecs As RasterCodecs) As String' Create a multi-page TIF fileDim pageFileName() As String = _{ _"C:\Users\Public\Documents\LEADTOOLS Images\Ocr1.tif", _"C:\Users\Public\Documents\LEADTOOLS Images\Ocr2.tif", _"C:\Users\Public\Documents\LEADTOOLS Images\Ocr3.tif", _"C:\Users\Public\Documents\LEADTOOLS Images\Ocr4.tif" _}Dim image As RasterImage = NothingFor i As Integer = 0 To pageFileName.Length - 1' load the page imageDim page As RasterImage = codecs.Load(pageFileName(i))If (i = 0) Then' first image, just save it into our variableimage = pageElse' add this page into our imageimage.AddPage(page)' we do not need this page anymorepage.Dispose()End IfNextDim outputFileName As String = "C:\Users\Public\Documents\LEADTOOLS Images\MultiPage.tif"If (File.Exists(outputFileName)) ThenFile.Delete(outputFileName)End Ifcodecs.Save(image, outputFileName, RasterImageFormat.Tif, 1, 1, 4, 1, CodecsSavePageMode.Overwrite)image.Dispose()Return outputFileNameEnd Function
string CreateMultiPageFile(RasterCodecs codecs){// Create a multi-page TIF filestring[] pageFileName ={@"C:\Users\Public\Documents\LEADTOOLS Images\Ocr1.tif",@"C:\Users\Public\Documents\LEADTOOLS Images\Ocr2.tif",@"C:\Users\Public\Documents\LEADTOOLS Images\Ocr3.tif",@"C:\Users\Public\Documents\LEADTOOLS Images\Ocr4.tif"};RasterImage image = null;for(int i = 0; i < pageFileName.Length; i++){// load the page imageRasterImage page = codecs.Load(pageFileName[i]);if(i == 0){// first image, just save it into our variableimage = page;}else{// add this page into our imageimage.AddPage(page);// we do not need this page anymorepage.Dispose();}}string outputFileName = @"C:\Users\Public\Documents\LEADTOOLS Images\MultiPage.tif";if(File.Exists(outputFileName))File.Delete(outputFileName);codecs.Save(image, outputFileName, RasterImageFormat.Tif, 1, 1, 4, 1, CodecsSavePageMode.Overwrite);image.Dispose();return outputFileName;}
|
Products |
Support |
Feedback: Splitting a Multi page TIFF File Tutorial |
Introduction |
Help Version 19.0.2017.6.21
|

Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.