Error: To many styles in the document

We are getting the error “Too many styles in
the document”. Looking through the forum this issue came up back in 2011 but I did not see any resolution. Is there a work around or fix for this issue? We just purchased your product as it passed our testing phase without seeing this error. This is a major issue for our clients and we need it fixed.

Hi Steven,


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

Moreover, I have verified this issue from our issue tracking system. We had logged this feature as WORDSNET-4173 in our issue tracking system. I have linked the forum thread to the same feature and you will be notified via this forum thread once this feature is available.

We apologize for your inconvenience.

Here's the code:

------------------------------------------------------------------------

Aspose.Words.Document file = null;

foreach (DOM.Classes.Letter letter in LettersToGroup)
{
if (file == null)
file = new Aspose.Words.Document(letter.OutputPath + ".docx");
else
file.AppendDocument(new Aspose.Words.Document(letter.OutputPath + ".docx"), ImportFormatMode.KeepSourceFormatting);
}

if (file != null)
file.Save(PdfPath);

Attached is a zip file with the docx templates. Out letter processor generates anywhere from 100’s to 1000’s of letters using these templates.


Then it runs the code from the earlier post to assemble these docx files together. That’s when we see the error.


We have found a work around for now to get the system to complete.Its a bit of a hack and would be better if we had direct control over removing duplicate styles or having Aspose detect duplicate styles and not adding to the Styles list if it is already there. Basically we noticed when trying to stich more than 2000 letters together the style list will start pitching fits. By the time we get through 1500 letters we are almost sure that all the styles we will ever need are in the list so we change the mode and carry on. Our other solution was to use Microsofts API and affect the styles list directly. To get through this quick so our customers are not impacted any more we implimented the following hack / work around

intcnt = 0;

ImportFormatMode mode = ImportFormatMode.KeepSourceFormatting;

            </p><p>foreach (DOM.Classes.Letter letter in LettersToGroup)</p><p>
            {</p><p>   <br>                    if (cnt++ > 1500)<br>                        mode = ImportFormatMode.UseDestinationStyles;<br><br>                    if (letter.OutputPath == null || !System.IO.File.Exists(letter.OutputPath))<br>                        throw new ArgumentNullException(string.Format("letter.OutputPath is null or file does not exist for {0} letter with path {1}", letter.TemplateName, letter.PdfPath));<br><br>                    if (letter.MarkedForEmail)<br>                        if (emailFile == null)<br>                            emailFile = new Aspose.Words.Document(letter.OutputPath + ".docx");<br>                        else<br>                            emailFile.AppendDocument(new Aspose.Words.Document(letter.OutputPath + ".docx"), mode);<br>                    else<br>                        if (file == null)<br>                            file = new Aspose.Words.Document(letter.OutputPath + ".docx");<br>                        else<br>                            file.AppendDocument(new Aspose.Words.Document(letter.OutputPath + ".docx"), mode);<br>                }</p>
1 Like
Hi Steven,

It is nice to hear from you that you have found the workaround of your problem. We always appreciate positive feedback from our customers. We will inform you via this forum thread once this feature (WORDSNET-4173) is available.

We appriciate your patience.

Hi Steven,


Thanks for your inquiry.

You may wish to restructure your code in order to avoid this exception all together. If you are stitching together documents that use the same style then you do not need to use KeepSourceFormatting as that would create duplicate identical styles. Instead in this case you can append all documents that use same styles together into one document using UseDestinationStyles and then append this to the different documents using KeepSourceFormatting.

Please let me know if this helps.

Thanks,

The issues you have found earlier (filed as WORDSNET-4173) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(14)

@sszelei

Starting from Aspose.Words 20.5, we added new feature to remove duplicate styles from the document using CleanupOptions.DuplicateStyle property. Following code snippet shows how to use this property.

Document doc = new Document(fileName);
CleanupOptions options = new CleanupOptions();
options.DuplicateStyle = true;
doc.Cleanup(options);
doc.Save(outFileName);