Document.append API throwing exception


#1

Hi,

We are using Document.append() API to merge two documents and I am getting following exception:
java.lang.IllegalStateException: There are too many styles in the document.

Please help what this exception mean and what should we do to avoid it.

Thanks
Manisha


#2

@oraspose,

Thanks for your inquiry. Have you tried the latest version of Aspose.Words for Java i.e. 19.9 on your end? In case the problem still remains, please ZIP and upload your input Word documents and piece of source code causing the exception here for testing. We will then investigate the issue on our end and provide you more information.


#3

Hi,

We are using Document.appendDocument() API to merge word documents and getting following exception:

Caused by: java.lang.IllegalStateException: There are too many styles in the document.

Please find the sample code below:

 public void testAppendDocument() throws Exception {
        Document target = new Document("Doc_1.docx");
        for (int i = 2; i < 11; i++) {
            String docName = "Doc_" + i + ".docx";
            Document source = new Document(docName);
            target.appendDocument(source
               ,ImportFormatMode.USE_DESTINATION_STYLES);
        }
        target.save("MergedDoc.docx");
    }

Please find the documents in attachments Aspose docs.zip (889.2 KB)
.

Thanks
Manisha


#4

@oraspose,

We tested the scenario and have managed to reproduce the same problem on our end. For the sake of correction, we have logged this problem in our issue tracking system. The ID of this issue is WORDSNET-19312. We will further look into the details of this problem and will keep you updated on the status of correction. We apologize for your inconvenience.


#5

Hi,

Do we have any further progress on this?

Can you provide some hints/workaround for this problem? Its a critical issue for us and we need to solve this problem.

Looking forward to your reply.

Thanks
Manisha


#6

@oraspose,

We have logged your concerns in our issue tracking system. At the moment, we are currently doing analysis of this issue (WORDSNET-19312) to determine the root cause. We will inform you via this thread as soon as this issue will be resolved in future or any workaround is available. We apologize for any inconvenience.


#7

Hi Hafeez,

We are not receiving email notifications regarding posts from last few weeks.
Please guide us if there is a way to enable it.

Thanks
Manisha


#8

@oraspose,

Sometimes emails may land in your Junk/Spam folder therefore please make sure to check these folders as well. Also, please make sure that your email server is not filtering/blocking emails coming from aspose.com’s servers.


#9

@oraspose,

Regarding WORDSNET-19312, it is to update you that we have completed the analysis of this issue. The error occurs because glossary documents of your documents contain large number of styles. When appending documents, the number of styles increases and exceeds the maximum allowable number of styles per document (4094).

For example, Doc_1.docx contains 2502 styles, Doc_2.docx contains 1366 styles. After appending Doc_2.docx, the target glossary document contains 2942 styles. Many of the styles are not actually used.

So, we can suggest the following (temporary) solution to you:

const string dir = "E:\\temp\\ASPOSE DOCS\\";
Document target = new Document(dir + "Doc_1.docx");

// Remove unused styles.
CleanupOptions cleanupOptions = new CleanupOptions();
cleanupOptions.UnusedLists = false;
target.Cleanup(cleanupOptions);

// Normalize internal style IDs.
target.Save(dir + "Tmp.docx");
target = new Document(dir + "Tmp.docx");

for (int i = 2; i < 10; i++)
{
    String docName = dir + "Doc_" + i + ".docx";
    Document source = new Document(docName);
    target.AppendDocument(source
        , ImportFormatMode.UseDestinationStyles);
}

target.Save(dir + "19.9.docx");

The target result document contains 2751 styles while limitation of the document format is 4094. If this solution will not fit in your real work, then we will try to implement a solution that combines and removes styles with a similar definition.

We will keep you posted on any further updates and let you know when this issue will be resolved in future.


#10

Thanks for looking into the issue and providing the workaround.

Is there any way to trigger the document clean up without saving the document afterwards?

// Remove unused styles.
CleanupOptions cleanupOptions = new CleanupOptions();
cleanupOptions.UnusedLists = false;
target.Cleanup(cleanupOptions);//Does this API not clean up the unused styles in the in-memory instance of target document?

// Normalize internal style IDs.
target.Save(dir + “Tmp.docx”); Is it possible to avoid saving the document here?

Thanks
Manisha


#11

@oraspose,

We have logged your concerns/questions in our issue tracking system and will keep you posted on any further updates.


#12

Hi,

Do we have any update on this?

Thanks
Manisha


#13

@oraspose,

I am afraid, there are no further updates available at the moment. We will inform you via this thread as soon as this issue will be resolved in future or any updates maybe available. We apologize for any inconvenience.


#14

@oraspose,

Regarding WORDSNET-19312, it is to update you that we are going to add normalize feature to Cleanup method. Currently, this feature is under development stage and if everything goes by plan, we are very hopeful to deliver it in the next release of Aspose.Words i.e. 19.11 (note: this estimate is not final at the moment).


#15

Hi,

Any idea when we can get fix on this issue? I don’t see its fix in Aspose.Words 19.11 version. Can we get it in Aspose.Words 19.12 version?

Thanks
Manisha


#16

@oraspose,

Unfortunately, your issue is not resolved yet.

We are not sure at the moment but we will inform you via this thread as soon as this issue will be resolved in future or any updates/estimates maybe available. We apologize for any inconvenience.


#17

@oraspose,

Regarding WORDSNET-19312, it is to update you that Style normalization was already implemented in 19.11 release. We just need confirmation from your end that style normalization actually helped you. Please try on your end (see my previous code) and tell us if the new behavior is acceptable for you? Thanks for your cooperation.