Maximum Allowed Number of Styles in Word Document 4094 - Too Many Styles Found in Glossary Document - Java

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

@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.

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

@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.

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

@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.

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

@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.

@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.

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

@oraspose,

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

Hi,

Do we have any update on this?

Thanks
Manisha

@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.

@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).

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

@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.

@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.

Hi,

We want to understand the “style normalization” feature implemented in Aspose.Words 19.11 version.

I have a document which has around 1378 styles defined in GlossaryDocument. After calling cleanUp API on this document, the styles (defined in GlossaryDocument) gets reduced to 377. But there are still many styles in glossary which are not used/referred anywhere. It seems they are redundant.

For example: The style with style id “E92C0304A7484F17A803167DC838F21D2” and style name “E92C0304A7484F17A803167DC838F21D2” is defined under GlossaryDocument but is not used anywhere. Similarly, style with style id “FC8ECB2DD8254D52BE6CEA25FF2104ED”. There are many such styles present in document not being used.

Why are these styles not cleaned by “cleanUp()” API?

Below is the code snippet used.

    public void testCleanup() throws Exception {
        Document doc=new Document("Doc_9.docx");
        GlossaryDocument gDoc=doc.getGlossaryDocument();
        System.out.println("no of styles in glossary before clean up is: "+gDoc.getStyles().getCount());
        doc.cleanup();
        doc.save("Doc_9_cleaned.docx");
        gDoc=doc.getGlossaryDocument();
        System.out.println("no of styles in glossary after clean up is: "+gDoc.getStyles().getCount());
    }

Please find the sample documents (used in the above code ) attachedAspose sample docs.zip (175.5 KB)

Please have a look at the problem discussed.

Looking forward to your reply.

Thanks
Manisha
.

@oraspose,

Thanks for the additional information. We have logged these details in our issue tracking system and will keep you posted on any further updates.

Hi,

Do we have any update on this?

Thanks
Manisha