Free Support Forum - aspose.com

Issue while converting Multi Frame TIFF image into PDF document

Hi,

I am using Aspose Total product in my project and I am facing issues while converting TIFF images with multiple pages into a PDF doc.
Here is the code, I am using.
TiffImage multiImage = (TiffImage) com.aspose.imaging.Image.load( << Image File Path>>);
int frameCounter = 0;
for (TiffFrame tiffFrame : multiImage.getFrames() )
{

multiImage.setActiveFrame(tiffFrame);
Color[] pixels = multiImage.loadPixels(tiffFrame.getBounds());
JpegOptions jpgCreateOptions = new JpegOptions();
jpgCreateOptions.setSource(new FileCreateSource(<>, false));
JpegImage jpgImage = (JpegImage)com.aspose.imaging.Image.create(jpgCreateOptions,tiffFrame.getWidth(),tiffFrame.getHeight());
{
jpgImage.savePixels(tiffFrame.getBounds(), pixels);
jpgImage.save();
Pdf pdf1 = new Pdf();
Section sec1 = pdf1.getSections().add();
aspose.pdf.Image img1 = new aspose.pdf.Image(sec1);
sec1.getParagraphs().add(img1);
img1.getImageInfo().setFile(<>);
pdf1.save(<<PDF_filename>>);
jpgImage.dispose();
}

While trying to load at this line,
“TiffImage multiImage = (TiffImage) com.aspose.imaging.Image.load”, the program hangs for some time and after that throws an exception as below,

com.aspose.imaging.exceptions.FrameworkException: Cannot allocate so many bytes. Use LoadPartialPixels instead.
at com.aspose.imaging.RasterImage$b.process(Unknown Source)
at com.aspose.imaging.RasterImage$c.process(Unknown Source)
at com.aspose.imaging.RasterImage$c.process(Unknown Source)
at com.aspose.imaging.internal.ch.t$a.a(Unknown Source)
at com.aspose.imaging.internal.bs.s.a(Unknown Source)
at com.aspose.imaging.internal.bs.s.a(Unknown Source)
at com.aspose.imaging.internal.ch.t.a(Unknown Source)
at com.aspose.imaging.internal.ch.ag.loadPixels(Unknown Source)
at com.aspose.imaging.RasterCachedImage.loadPixelsInternal(Unknown Source)
at com.aspose.imaging.RasterImage.a(Unknown Source)
at com.aspose.imaging.RasterImage.a(Unknown Source)
at com.aspose.imaging.RasterImage.loadPartialPixels(Unknown Source)
at com.aspose.imaging.fileformats.tiff.TiffImage.loadPixelsInternal(Unknown Source)
at com.aspose.imaging.RasterImage.a(Unknown Source)
at com.aspose.imaging.RasterImage.a(Unknown Source)
at com.aspose.imaging.RasterImage.loadPixels(Unknown Source)

Is this a known issue? I was searching in the forum and came to know that there was indeed an issue with multipage tiff images for Aspose Java.
Please help. This issue is blocking further processing as well.

P.S. - If anyone needs the TIFF image, I am trying to convert, please give me your email ID. I’ll send it to you.

Thanks,
Wasim

Hi,

Just noticed that my application now is not even throwing an exception. It simply remains hanging at this line. :((

"TiffImage multiImage = (TiffImage) com.aspose.imaging.Image.load( << Image File Path>>);"

Thanks,
Wasim

Hi Wasim,


Thank you for contacting Aspose support.

We need your sample image along with your environment details to properly investigate your presented scenario on our end. Please use the contact button on the post window to send an email to babar.raza, and attach your sample image to the email message. Please also share the following information.

  • Operating system version
  • Operating system architecture
  • JDK type
  • JDK version

Please confirm here after sending the email message so that your message isn’t lost in spam mails.

Hi,
Thanks for replying.
I have sent the image to your mail as instructed. My system details are :
OS version: windows server 2008 R2 standard
OS Arch: 64 bit machine
JDK type: 64 bit
JDK version: 7 update 60

Attached are the details.

Please let me know if you need any more info.

Thanks,
Wasim

Hi Wasim,


Thank you for sharing your system details and the sample image. I am sorry, I have forgot to ask a key information, that is; the version of Aspose.Imaging for Java you are currently using.

Anyway, I have quickly performed a few tests on Windows 7 Home Premium with JDK 1.7.0_65 & 1.8.0_20 while using the latest version of Aspose.Imaging for Java 2.6.0. Unfortunately, I am unable to observe any exception or hanging issue so far. I moving forward to test the same on Windows Server 2008 R2. I will keep you posted with updates in this regard.

In the meanwhile, please try this case against the latest version of Aspose.Imaging for Java 2.6.0, and feed us back with your results.

Hi Babar,

How to check the Aspose Imaging version? We have Aspose.Total for Java license.

20160623
3.0

Does it help?

Thanks,
Wasim

Hi Wasim,


The version is mentioned in the API Jar file as aspose-imaging-(version number)-jdk1x.jar. You may also get the version information using the following statement in your Java application.

Java

System.out.println(com.aspose.imaging.BuildVersionInfo.ASSEMBLY_VERSION);

It is aspose-imaging-2.1.0.0-jdk16

Hi Wasim,


Thank you for the confirmation.

Aspose.Imaging for Java 2.1.0 is an old revision and probably the issue is specific to that version. I am setting up Windows Server 2008 R2 on a virtual machine to confirm my suspicion, however, it will take some time. You already have the required environment on you end so could you please download the latest Jars from the link shared earlier, and give your scenario another try while referencing Aspose.Imaging for Java 2.6.0 in your project.

Ok, will check and let you know.

Could you please also inform how to get the latest updates for licensed Aspose products. Do we have to download the jars and use?
-Thanks

Hi,

I tried with aspose-imaging-2.6.0-jdk16.jar as you suggested but it threw the same exception,

Tiff convert error. Saving as blank page :TESTCOPY.TIF
class com.aspose.imaging.exceptions.FrameworkException: Cannot allocate so many bytes. Use LoadPartialPixels instead.
com.aspose.imaging.RasterImage$e.process(Unknown Source)
com.aspose.imaging.RasterImage$f.process(Unknown Source)
com.aspose.imaging.RasterImage$f.process(Unknown Source)
com.aspose.imaging.internal.cs.a$a$h.a(Unknown Source)
com.aspose.imaging.internal.bm.I.a(Unknown Source)
com.aspose.imaging.internal.bm.I.a(Unknown Source)
com.aspose.imaging.internal.cs.a$a.a(Unknown Source)
com.aspose.imaging.internal.bm.I.a(Unknown Source)
com.aspose.imaging.internal.bm.I.a(Unknown Source)
com.aspose.imaging.internal.cs.a.a(Unknown Source)
com.aspose.imaging.internal.cp.d.loadPartialPixels(Unknown Source)
com.aspose.imaging.RasterImage$b.a(Unknown Source)
com.aspose.imaging.internal.bm.I.a(Unknown Source)
com.aspose.imaging.internal.bm.I.a(Unknown Source)
com.aspose.imaging.RasterImage.loadPixelsInternal(Unknown Source)
com.aspose.imaging.RasterImage.a(Unknown Source)
com.aspose.imaging.RasterImage.a(Unknown Source)
com.aspose.imaging.RasterImage.loadPartialPixels(Unknown Source)
com.aspose.imaging.fileformats.tiff.TiffImage$a.loadPartialPixels(Unknown Source)
com.aspose.imaging.RasterImage$b.a(Unknown Source)
com.aspose.imaging.internal.bm.I.a(Unknown Source)
com.aspose.imaging.internal.bm.I.a(Unknown Source)
com.aspose.imaging.RasterImage.loadPixelsInternal(Unknown Source)
com.aspose.imaging.RasterImage.a(Unknown Source)
com.aspose.imaging.RasterImage.a(Unknown Source)
com.aspose.imaging.RasterImage.loadPixels(Unknown Source)
sg.apl.q2c.asposejava.ScanNewEmail.processAttachment(ScanNewEmail.java:489)
sg.apl.q2c.asposejava.ScanNewEmail.processEmailFolder(ScanNewEmail.java:285)
sg.apl.q2c.asposejava.ScanNewEmail.run(ScanNewEmail.java:89)
java.lang.Thread.run(Unknown Source)
at com.aspose.imaging.RasterImage$e.process(Unknown Source)
at com.aspose.imaging.RasterImage$f.process(Unknown Source)
at com.aspose.imaging.RasterImage$f.process(Unknown Source)
at com.aspose.imaging.internal.cs.a$a$h.a(Unknown Source)
at com.aspose.imaging.internal.bm.I.a(Unknown Source)
at com.aspose.imaging.internal.bm.I.a(Unknown Source)
at com.aspose.imaging.internal.cs.a$a.a(Unknown Source)
at com.aspose.imaging.internal.bm.I.a(Unknown Source)
at com.aspose.imaging.internal.bm.I.a(Unknown Source)
at com.aspose.imaging.internal.cs.a.a(Unknown Source)
at com.aspose.imaging.internal.cp.d.loadPartialPixels(Unknown Source)
at com.aspose.imaging.RasterImage$b.a(Unknown Source)
at com.aspose.imaging.internal.bm.I.a(Unknown Source)
at com.aspose.imaging.internal.bm.I.a(Unknown Source)
at com.aspose.imaging.RasterImage.loadPixelsInternal(Unknown Source)
at com.aspose.imaging.RasterImage.a(Unknown Source)
at com.aspose.imaging.RasterImage.a(Unknown Source)
at com.aspose.imaging.RasterImage.loadPartialPixels(Unknown Source)
at com.aspose.imaging.fileformats.tiff.TiffImage$a.loadPartialPixels(Unknown Source)
at com.aspose.imaging.RasterImage$b.a(Unknown Source)
at com.aspose.imaging.internal.bm.I.a(Unknown Source)
at com.aspose.imaging.internal.bm.I.a(Unknown Source)
at com.aspose.imaging.RasterImage.loadPixelsInternal(Unknown Source)
at com.aspose.imaging.RasterImage.a(Unknown Source)
at com.aspose.imaging.RasterImage.a(Unknown Source)
at com.aspose.imaging.RasterImage.loadPixels(Unknown Source)

Please look into it.

Thanks,
Wasim

Hi Wasim,

We are sorry to know that the latest version of Aspose.Imaging for Java 2.6.0 hasn't helped you. Please allow me some time to test the case on Windows Server 2008 R2 and get back to you with updates in this regard.

Itsak26:
Ok, will check and let you know.

Could you please also inform how to get the latest updates for licensed Aspose products. Do we have to download the jars and use?

Yes, you can download the latest revisions of Aspose APIs from the Aspose download section. As per your license subscription expiry mentioned in this thread, you are entitled to use any release of Aspose for Java APIs till 23rd June 2016.

Hi Babar,

Thanks for the info.
Yes, please look into case as soon as possible. The thing is if the application throws Exception, it can be handled but the biggest issue is sometimes the program hangs there and all further processing gets blocked and application needs restart. Can you suggest a work-around for the same for the time being from the code I sent to you?

Thanks,
Wasim

Hi Wasim,


I have tested the case on Windows Server 2008 R2 with JDK 1.7.0_65 against the latest version of Aspose.Imaging for Java 2.6.0. I am afraid, I am unable to experience any exception or the hanging issue on my side while loading your provided sample image (please confirm the provided sample is the one causing the issue on your side). Please note, I have created a virtual machine by installing the operating system from scratch.

At the moment, I am not sure why you are experiencing the problems that I am unable to replicate, however, I have the insight of error FrameworkException: Cannot allocate so many bytes. Use LoadPartialPixels instead. The said problem is caused due to reason that the CLR runs out of memory, and at some point cannot allocate the Color[width * height] array to return. When such situation occurs the Aspose.Imaging APIs start the partial processing loop by allocating a smaller rectangle of pixels (like Color[width * height/2]; typical algorithm is subject to change) and passing that smaller rectangle along with pixels to the processing application via the IPartialPixelLoader interface. We will further investigate this case on our end, in the meanwhile, it is suggested that you should use the CacheType.CacheOnDiskOnly settings to allocate the space on disk to store the pixels for testing purposes.

Please add the following statements at the start of your application to see if it could resolve the issue.

Java

Cache.setCacheType(CacheType.CacheOnDiskOnly);
Cache.setCacheFolder(temporaryFolderLocation);

Hi Wasim,


I have further discussed this matter with the product team, and we believe the problem is most likely related to the dimensions of the image. The Aspose.Imaging for Java API is unable to load the file (using PartialPixels) due to the lack of available memory. In case the available memory is sufficient to load the pixels of this sample when then such exception can occur due to the unavailability of the free memory block of required size. Please note, for the image of dimension 5100x6600 approximately 800 megabytes of memory is required to hold the image data (24bytes for each pixel on x64 machine).

In order to fix this issue, please gradually increase the Java Heap size for your application and see which value suits the application needs for this particular sample. Please note, on my machine the max size is set to Xmx256m and I am unable to replicate the said exception with this sample.

Hi Babar,

I checked my application and these are my JVM settings during startup. So, I think the memory should be fine.

REM JVM configuration
set PR_JVMMS=256
set PR_JVMMX=1024
set PR_JVMSS=4000

Thanks,
Wasim
+919874636222

Hi Wasim,


I would request you to please perform a test by creating a simple console application in the same environment while setting the Java Heap size to 256MB (even lower). See if you can load the sample image without error. In case the issue persists, try again by increasing the size gradually. I have tested on my end (both on Windows 7 & 2008 R2), the said sample can be loaded without throwing any exception. I believe the image loading process on your side is part of a big application that overall consume much more memory whereas performing the isolated tests in the same environment will help you troubleshoot this scenario further.

Hi Babar,

Okay, will do that. Meanwhile I was testing with another Image file and I got this exception.

com.aspose.imaging.exceptions.ImageLoadException: Image loading failed.
at com.aspose.imaging.Image.a(Unknown Source)
at com.aspose.imaging.Image.load(Unknown Source)
at sg.apl.q2c.asposejava.ScanNewEmail.processAttachment(ScanNewEmail.java:495)
at sg.apl.q2c.asposejava.ScanNewEmail.processEmailFolder(ScanNewEmail.java:294)
at sg.apl.q2c.asposejava.ScanNewEmail.run(ScanNewEmail.java:89)
at java.lang.Thread.run(Unknown Source)
Caused by: class com.aspose.imaging.internal.Exceptions.SystemException: com.aspose.imaging.exceptions.ImageLoadException: Unable to read file. Exception:Error loading file: Unsupported file format
Parameter name: input —> com.aspose.imaging.exceptions.ImageLoadException: Unable to read file. Exception:Error loading file: Unsupported file format
Parameter name: input

Why the aspose is throwing unsupported file exception with the attached TIF file? Could you please check.
Thanks,
Wasim

Hi Wasim,


I am afraid, I am unable to observe any exception while loading the sample image UKCedit.tif against the latest version of Aspose.Imaging for Java 2.6.0. However, the Aspose.Imaging for Java 2.1.0 does trigger the ImageLoadException: Unable to read file. Exception:Error loading file: Unsupported file format. Parameter name: input at Image.load method. Please upgrade the API because with the latest revisions of the API we have provided support for many TIFF compression methods that were not supported before.

Regarding the original concerns as discussed in this thread, I would request you to perform all your testing against the latest version of the API, and not with 2.1.0 (your current version).

Hi Babar,

Regarding your earlier suggestion about gradual increase of Java heap size, I created one sample application and observed the same issue of “com.aspose.imaging.exceptions.FrameworkException: Cannot allocate so many bytes. Use LoadPartialPixels instead”. at 128m memory.
I increased the JVM heap size from 128m till 1024m gradually but the exception didnt go. My system didnt allow me to go further than 1024m.
Is there any other way to load a large pixel image in Aspose imaging API list?

Thanks,
Wasim