Hello,
I’m making a program that can take a template and duplicate it in one word doc as needed. I can get it to make 5000+ page documents, but when I try to open them in Word (2003) it won’t open them. The highest amount of pages that I can get to open is 4080. Is there anything known issues or problems with opening large word documents? Or something wrong with my code? I was looking to just get to a limit of 5000 page documents. (See attached. I also attached the word document that works and one that doesn’t in the zip file.)
Note: I tested doing this with just one line in the template page and got these results and also tested doing this with a normal one-page document like a letter.
Hi,
So far I can't recall any issues related to the number of pages in the document as well as any limitations. I remember a customer worked with a document contained 20K pages and it was ok. However, your 4125 pages document does freeze Microsoft Word 2003 when I try ro open it. I have logged this as issue #1389 and we will see what could be done. Thank you.
I think I understand what's going on.
There could be maximum 4097 (or so) styles in a Microsoft Word document because style identifiers are 12-bit internally.
When import from one document to another like you do, using
objDest = m_objDocBuilder.Document.ImportNode(objSource, True, ImportFormatMode.KeepSourceFormatting)
This creates new styles in the destination document. You can see that in the document if you open it in MS Word, there are styles Normal_2, Normal_3, ... Normal_4050 and so on. There is no check in Aspose.Words for style identifier overflow (I will add one in the next hotfix).
You need to change the way you copy the document if you want your code to work. You can either change to use ImportFormatMode.UseDestinationStyles option (this might or might not be suitable depending on the formatting you have). Alternatively, you should create a NodeImporter object and pass it into every ImportNode call. The NodeImporter object will serve as an import context and styles will be imported only once. At the moment you basically import styles over and over again 5000 times.
I hope that helps.