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

Free Support Forum - aspose.com

Saving MSG/EML as PDF java.lang.OutOfMemoryError

Hi,
I have an email with an inline image in the body.
I have been following the guide below

https://docs.aspose.com/display/emailjava/Saving+A+MSG+as+PDF

eml.save(emlStream, SaveOptions.getDefaultMhtml());

The above line consistently causes one of two errors:
Caused by: java.lang.OutOfMemoryError: Java heap space
Caused by: java.lang.OutOfMemoryError: GC overhead limit exceeded

Below is an extract of one of the times:
Caused by: java.lang.OutOfMemoryError: GC overhead limit exceeded
at sun.text.normalizer.UCharacterIterator.getInstance(UCharacterIterator.java:84)
at sun.text.normalizer.NormalizerBase.setText(NormalizerBase.java:1002)
at java.text.CollationElementIterator.setText(CollationElementIterator.java:505)
at java.text.RuleBasedCollator.compare(RuleBasedCollator.java:383)
at com.aspose.email.internal.k.a.b(Unknown Source)
at com.aspose.email.internal.k.a.a(Unknown Source)
at com.aspose.email.internal.k.a.a(Unknown Source)
at com.aspose.email.internal.b.aq.b(Unknown Source)
at com.aspose.email.internal.b.aq.f(Unknown Source)
at com.aspose.email.MhtMessageFormatter.a(SourceFile:635)
at com.aspose.email.MhtMessageFormatter.format(SourceFile:480)
at com.aspose.email.MailMessage.a(SourceFile:5691)
at com.aspose.email.MailMessage.a(SourceFile:2311)
at com.aspose.email.abd.a(SourceFile:2365)
at com.aspose.email.internal.eg.a.a(Unknown Source)
at com.aspose.email.internal.eg.b.a(Unknown Source)
at com.aspose.email.MailMessage.save(SourceFile:2363)
at xxx.xxx.xxx.xxx.xxx.EmailContentSplitter.split(EmailContentSplitter.java:58)

I will attach two example .msg files which I get the issue with.
exampe-msgs.zip (35.2 KB)

Below are my memory VM options:
-Xms256m
-Xmx1024m
-XX:PermSize=256m
-XX:MaxPermSize=384m

Is there an issue in the code that handles the save?
Are there any alternative methods of doing the same task?

@Priyesh,

Could you please confirm if you are using the latest version of the API at your end? We have tested your sample files with the latest version of the API at our end and are not able to reproduce the problem at our end. Please try it with the latest version of the API and let us know your feedback.

Thanks for your fast response, we are currently using version 6.8.0. I will update to version 17.7 and give it another go.

@kashif.iqbal
We have tried with 17.7 and get the same result.
It takes around 10 mins, and then ends up running out of memory (this was tested with the inline image.msg 43Kb file in the zip i attached in my original post).

Caused by: java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2367)
at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:130)
at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:114)
at java.lang.AbstractStringBuilder.insert(AbstractStringBuilder.java:973)
at java.lang.StringBuilder.insert(StringBuilder.java:291)
at com.aspose.email.internal.b.an.a(Unknown Source)
at com.aspose.email.MhtMessageFormatter.a(SourceFile:1233)
at com.aspose.email.MhtMessageFormatter.a(SourceFile:880)
at com.aspose.email.MhtMessageFormatter.format(SourceFile:684)
at com.aspose.email.MailMessage.a(SourceFile:5604)
at com.aspose.email.MailMessage.a(SourceFile:2023)
at com.aspose.email.adf.a(SourceFile:2077)
at com.aspose.email.internal.eg.a.a(Unknown Source)
at com.aspose.email.internal.eg.b.a(Unknown Source)
at com.aspose.email.MailMessage.save(SourceFile:2075)

@Priyesh,

We have tested the scenario with the following settings and no issue is observed.

-Xms256m
-Xmx1024m
-XX:PermSize=256m
-XX:MaxPermSize=384m

You may please test the sample code on some other machine as well. Also please ensure that you are using latest version of both Aspose.Email and Aspose.Words during testing. If issue is not re-produced, please increase your VM heap sizes and test the scenario again. I am afraid that until and unless this issue is not re-produced here, it will be difficult to provide assistance in this regard.

We are currently using 17.6 for words and 17.7 for email.

As stated in the original post the line that causes this issue is:
eml.save(emlStream, SaveOptions.getDefaultMhtml());

Therefore it cannot be related to Aspose-Words as it cannot get to the line of code that is related to the Aspose-words.jar

I will perform the test you requested, may I ask what JDK was used to test this on your end?
The version of our application that we are seeing this issue in is using JDK1.7.

I will also perform the same test with JDK 1.8.

@Priyesh,

I have tested it using JDK 1.8.0_131. Please feel free to write us back if you have any other query related to Aspose.Email for Java.

@kashif.iqbal

Hi Kashif,

Thanks for your help and patience with this, I have managed to locate the issue and it was the calling code that was causing the problem I was having.

@Priyesh,

You are welcome and please feel free to write to us if you have any further query related to the API.

what was the issue?
i am facing same problem.
please help

Hi Amrit,

So following the guide https://docs.aspose.com/display/emailjava/Saving+A+MSG+as+PDF, the only thing we had to add is load options to the the following call:
MailMessage eml = MailMessage.load(fstream);

the above became:
final LoadOptions loadOptions;
if(FileFormat.EML.getMimeType().equals(emailDocument.getMimeType())){
loadOptions = new EmlLoadOptions();
((EmlLoadOptions) loadOptions ).setPreserveTnefAttachments(false);
} else {
loadOptions = new MsgLoadOptions();
((MsgLoadOptions) loadOptions ).setPreserveTnefAttachments(false);
}
final MailMessage mailMessage = MailMessage.load(new ByteArrayInputStream(emailDocument.getData()),loadOptions);

Everything else worked as expected once loadOptions were set.

I hope this helps.
Sorry for not adding this to the post last year.

Thanks,

thanks a lot. its working fine now.
Thanks again