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

Free Support Forum - aspose.com

Problem when saving large word files


An “OutOfMemoryError” exception is thrown when I try to update the table of contents and save the word file (28,9 Mo).

Java argument : -Xms1536m

Code source :
LoadOptions lOption = new LoadOptions(LoadFormat.WORD_ML, “”, “”);
Document contentsDoc = new Document(“contents.doc”, lOption);
Document doc = new Document(“document.doc”, lOption);

contentsDoc.appendDocument(doc, ImportFormatMode.KEEP_SOURCE_FORMATTING);


Exception :
Exception in thread “main” java.lang.OutOfMemoryError: Java heap space
at com.aspose.words.u.d(BbtNode.java:94)
at com.aspose.words.s.b(Bbt.java:393)
at com.aspose.words.asx.g(StoryLayoutBuilder.java:56)
at com.aspose.words.asv.a(StoryCloner.java:56)
at com.aspose.words.rk.a(HeaderFooterStories.java:55)
at com.aspose.words.rl.c(HeaderFooterStoryLayout.java:91)
at com.aspose.words.aiu.h(PageReflower.java:41)
at com.aspose.words.ajj.w(PartReflower.java:31)
at com.aspose.words.asw.fb(StoryLayout.java:90)
at com.aspose.words.ff.aE(DocumentLayoutBuilder.java:169)
at com.aspose.words.wc.a(LayoutDocument.java:52)
at com.aspose.words.Document.updatePageLayout(Document.java:1461)
at com.aspose.words.ld.perform(ExternalActionUpdateLayout.java:25)
at com.aspose.words.os.execute(FieldUpdateExecutionItem.java:79)
at com.aspose.words.ov.if(FieldUpdater.java:97)
at com.aspose.words.ov.updateFields(FieldUpdater.java:60)
at com.aspose.words.Range.updateFields(Range.java:172)
at com.aspose.words.Document.updateFields(Document.java:1047)
at aspose.task.print.GenerateDocProcessTask.main(GenerateDocProcessTask.java:233)

How to resolve this problem, please?

Hi Antoine,

Thanks for your inquiry. Could you please attach your input documents here for testing? I will investigate the issue on my side and provide you more information.

Best Regards,

Thanks for your quick reply, very much appreciated.

I have attached the requested documents/files in the attached zip file.
I look forward to your response.

Best Regards,


Hi Antoine,

First of all, please note that DocumentExplorer is a very useful tool which easily enables us to see the entire document structure. You can find DocumentExplorer in the folder where you installed Aspose.Words e.g. C:\Program Files (x86)\Aspose\Aspose.Words for .NET\Demos\CSharp\DocumentExplorer\bin\DocumentExplorer.exe. Below is the DOM structure of your document as viewed with DocumentExplorer:

Provided Word document truncated at the end. To utilize Aspose.Words on its full capacity, you can apply an evaluation license without restrictions for 30 days here.

I just remove first empty paragraph in second section and exception could not occur again on my side. I have attached input / output Word documents.


Have you really tested my input document?
because it seems your document is truncated and does not contain 3000 pages.

I have a temporary licence and it does not truncate the document.

I don't understand why you have removed the first empty paragraph in second section.

Could you rerun the test with the complete document (28,9Mo), please?

Best Regards,


Thanks for your inquiry.

While using the latest version of Aspose.Words i.e. 11.0.0 and your code, I managed to reproduce this exception on my side. Most likely this problem occurs because the document you are trying to append to another document is simply too large. You should note that usually Aspose.Words needs few times more memory than document size to build model of the document (DOM) in memory.

For example if your document’s size is 1 MB, Aspose.Words needs 10-20 MB of RAM to build its DOM in memory. Multiplier depends on format because some formats are more compact than others. For example DOCX format is more compact than DOC and RTF, and DOC is more compact than RTF.

So I am not sure the issue you reported can be resolved in Aspose.Words. I would advise you to use few small documents instead of one huge document. Also, please try stopping all running service/programs on your machine while performing this operation (appending, updating fields and then saving).

Please let me know if I can be of any further assistance.

Best Regards,

Hi Antoine,

Thank you for inquiry. Moreover, Please view the attached screenshot.

Here, you can observe input Word document text truncated after 4 pages so the Document Explorer don’t recognize whole text (along with 3000 pages).

In case of any ambiguity, please let me know.


Thanks very much for your replies.

Do you think I will have the same problem using Aspose.Words for. NET?
Please, could you test the large word document with Aspose.Words for .Net and tell me if the generated file was working correctly?

I look forward to your answer.

Best Regards,


Thanks for your request. I was able to successfully perform the desired task (i.e. append/save) on the .Net platform without any exception. I have slightly modified your code below that worked for me:

Document doc = new
Document contentsDoc = new Document(@“c:\Aspose\contents.doc”);

contentsDoc.AppendDocument(doc, ImportFormatMode.KeepSourceFormatting);

However, the exception did occur on my side when I didn’t specify SaveFormat in the Save method.

If we can help you with anything else, please feel free to ask.

Best Regards,

I try to use the "SaveFormat" option with Aspose.Words for java and i append/save the large word file with success.
I was able to generate the large file (docx, doc and pdf) without any exception.

Thanks for your time!

Best Regards,

Hi Antoine,

Thanks for your feedback. It is perfect that you managed to resolve the problem on your side. If we can help you with anything else, please feel free to ask.

Best Regards,