I have tried to use the sample code but its not complete and missing dependencies. Can you please share the working sample code and please first try using latest Aspose.Imaging for Java 21.2 on your end as well.
This is the code. Thanks for your help. It looks like the page 6 caused the issue but i don’t know how to fix it. Maybe you can take a look to see if there is any workaround. thanks/kevin
public static void main(String[] args) {
var pages = 98;
com.aspose.imaging.fileformats.tiff.TiffImage [] images = new com.aspose.imaging.fileformats.tiff.TiffImage[pages];
com.aspose.imaging.fileformats.tiff.TiffImage image = null;
try {
for (var p = 0; p < pages - 1; p++) {
log.info("Loading tiff page # " + p + " ... ");
images[p] = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.fileformats.tiff.TiffImage.load("C:\\Temp\\5440581\\5440581_" + (p+2) + ".tif");
}
var firstPage = "C:\\Temp\\5440581\\5440581" + "_1.tif";
image = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.fileformats.tiff.TiffImage
.load(firstPage);
for (var p = 0; p < pages - 1; p++) {
log.info("Merging tiff page # " + p + " ... ");
TiffFrame frame = TiffFrame.copyFrame(images[p].getActiveFrame());
image.addFrame(frame);
}
log.info("Saving tiff ... ");
image.save("C:\\Temp\\5440581" + ".tif");
} catch (Exception e) {
e.printStackTrace();
}
I have been able to verify the issue on saving the Tiff. A ticket with ID IMAGINGJAVA-2055 has been created to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.
We have investigated the issue. The problem is in one corrupted tiff (5440581_6.tif). You can check it opening 5440581_6.tif with any viewer. In order to avoid this issue, you may please need use LoadOptions.DataRecoveryMode. Please use followed code.
// TODO code application logic here
String path="/Users/mudassirkhan/Downloads/5440581/";
String licpath="/Users/mudassirkhan/Downloads/";
License lic = new License();
lic.setLicense(licpath+"Conholdate.Total.Java.lic");
int pages = 98;
com.aspose.imaging.fileformats.tiff.TiffImage[] images = new com.aspose.imaging.fileformats.tiff.TiffImage[pages-1];
com.aspose.imaging.fileformats.tiff.TiffImage image = null;
try
{
// This code allows us to process any corrupted tiff files without exception.
LoadOptions lop = new LoadOptions();
lop.setDataRecoveryMode(DataRecoveryMode.ConsistentRecover);
for (int p = 0; p < pages - 1; p++)
{
System.out.println("Loading tiff page # " + p + " ... ");
images[p] = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.fileformats.tiff.TiffImage.load(path + "5440581_" + (p+2) + ".tif", lop);
}
String firstPage = path + "5440581" + "_1.tif";
image = (com.aspose.imaging.fileformats.tiff.TiffImage) com.aspose.imaging.fileformats.tiff.TiffImage.load(firstPage);
for (int p = 0; p < pages - 1; p++)
{
System.out.println("Merging tiff page # " + p + " ... ");
TiffFrame frame = TiffFrame.copyFrame(images[p].getActiveFrame());
image.addFrame(frame);
}
System.out.println("Saving tiff ... ");
image.save(path + "Mudasir_5440581" + ".tif");
}
finally
{
if (image != null)
image.close();
for (TiffImage tiffImage : images)
{
if (tiffImage != null)
tiffImage.close();
}
}