We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Split tiff file

hello, I would like to know if you have a java product which allow us to split multipage .tiff file on separate .tiff file. Our need is to scan to a multipage .tiff page with several barre code (1 barcode by page maximum.). Each time that we detect a barcode, we split the .tiff file.

Hi Vincent,

Thank you for considering Aspose products, and welcome to the Aspose.Imaging support forum.

Aspose.Imaging for Java is capable of loading multipage Tiff images, and can extract individual frames. These extracted frames can be saved in different file formats as per requirement. Below provided sample code demonstrate the usage of Aspose.Imaging API to extract the individual Tiff frames to separate Tiff images. Please download an evaluation copy of Aspose.Imaging for Java v1.8.0, and give it a try on your end.

Java


//Load a multipage Tiff
TiffImage multiImage = (TiffImage) Image.load(myDir
+ “Lorem ipsum dolor sit amet (Resolution 200).tiff”);
//Initialize an integer to keep track of Tiff Frames
int frameCounter = 0;
//Iterate over the Tiff Frame Collection
for (TiffFrame tiffFrame : multiImage.getFrames())
{
//Set the Tiff Frame to be Active for processing
multiImage.setActiveFrame(tiffFrame);
//Load all pixels of Tiff Frame in an array of type Color
Color[] pixels = multiImage.loadPixels(tiffFrame.getBounds());
//Create an instance of TiffOptions; This will create files for each frame
TiffOptions createOptions = new TiffOptions();
//Set the source for TiffOptions; Passing FileCreateSource in this case
createOptions.setSource(new FileCreateSource(String.format(myDir
+ “Frame-” + frameCounter + “.tiff”), false));
//Create an image of Tiff Frame size
TiffImage tiffImage = (TiffImage) Image.create(createOptions,
tiffFrame.getWidth(), tiffFrame.getHeight());
{
//Save the pixels of Tiff Frame to newly created Tiff image
tiffImage.savePixels(tiffFrame.getBounds(), pixels);
//Save the image to disk
tiffImage.save();
}
frameCounter++;
}
Please feel free to write back in case you feel any difficulty, we would be glad to help you out.

Useful Links:

  • API Reference Guide

hi babar.raza,


i want to split multi page tiff file with your aspose imaging jar. i looked at the above code but i didn’t do it.

Exception in thread “main” java.lang.OutOfMemoryError: Java heap space
at com.aspose.imaging.RasterImage.a(Unknown Source)
at com.aspose.imaging.RasterImage.a(Unknown Source)
at com.aspose.imaging.RasterImage.loadPixels(Unknown Source)
at com.asposesplit.SplitApp.pdf(SplitApp.java:36)
at com.asposesplit.SplitApp.main(SplitApp.java:23)

could you help us,

thanks.

Hi Cyber,


Thank you for contacting Aspose support.

You are probably loading a large sized Tiff image due to which the Java Heap set for your environment is proving to be insufficient. We would suggest you to increase the Java Heap size to at least 512 or more if your machine has plenty of RAM. In case the problem persists, please provide us the problematic sample so we could evaluate the issue as a bug on the part of Aspose.Imaging for Java API.