Free Support Forum -

Doc building/merging - crashing WOrd

I am having trouble building up a document by merging other documents together. Basically the document is created properly, but will crash Word (both 2k and 2003) at different points when trying to do things. The problem occurs by the copying/moving of sections. Many approaches were tried, the last two as below. Note the docs attached differ slightly in content, as a result of numerous tests. However, the same behaviour was observed on identical documents…

Clone Code : Implemented this way, the document is fine, you can save it and do other things. You can also print it out completely. However, AFTER you print it out and go to close the particular document (or Word itself) - Word crashes. This behaviour was using the following code and can be observed in the resulting output document called OkUntilPrintAndClose.doc

For Each sec As Aspose.Word.Section In fromDoc.Sections
Dim newSec As Aspose.Word.Section = toDoc.Sections(0).Clone

Alternate Clone Code: This method crashes when you try and print the document (see document CrashOnPrint.doc) - so the first version is more useful

For Each sec As Aspose.Word.Section In from.Sections

The same problem occurs on Apose.Word versions v3 and v2.5.2. It happens with Word 2k, 2003 and occurs on several different machines.

I’ve read the forums and realise this might not be the best way to use Aspose.Word, but we are running behind schedule and don’t really have time to refactor. However, since it ‘almost’ works I am hoping there can be a quick work around…

Any help is appreciated

Can you please post the original documents that are not yet damaged, it will let me find and fix the problem faster.

Attached are the docs that cause the problem.

I have tried simply running a merge on each doc separately (without combining them) and the output is all good.

I have also tried a) using aspose to copy the styles between docs and b) manually adding them all together in a big doc that functions; then deleting the content (i.e. creating a working, empty default document) and adding the data on the fly. No go.

THanks for your help

any luck??

Thanks for the attachment, we’re looking into the issue.

The problem is caused by the floating pictures in the header that are used as a background. This is something that we are really going to fix in Aspose.Word - it cannot properly duplicate floating images.

In your case you have three or more documents to join, all of them have same floating picture in the background. Each floating shape has an internal identifier, it is the same in all documents. When you simply combine the documents the result is a document that contains several floating shapes with the same identifier - not really a best shot and sometimes causes printing problems for MS Word.

In most cases it is easy to change something in the template or change the approach to work around the problem, but there are several options each applicable for different scenarios.

Here is a solution for you: clear headers footers in all of the documents that you append to the first document so they are linked to the first page header/footer and the floating image will not be duplicated.

Document doc1 = TestUtil.Open(@“Other\Jat\APreview.doc”);
Document doc2 = TestUtil.Open(@“Other\Jat\BCPreview.doc”);

foreach (Section oldSection in doc2)
Section newSection = (Section)doc1.ImportNode(oldSection, true);

//This makes new section headers and footers to link to previous
//and avoid the problem of duplicating floating images.


TestUtil.Save(doc1, @“Other\Jat\TestJatCombine Out.doc”);

thanks for your help. I knew it was some issue with our templates but was unsure on how to diagnose the fault. The Word 2003 ‘repair doc’ feature isn’t very easy to work out what went wrong.

I will implement your solution on Monday. Thanks for the response.

Unfortunately the same problem occurs EVEN with the sample code you provide.Crying

Actually, with the sample code it does infact print out; HOWEVER once you have finished printing it out, if you go to close the document, the Word then crashes. If you do not print out the document, you are able to close word fine - it is only after the print does word crash.

Similar behaviour happens as well with this code in Aspose.Word v2.5.2 (the version we'd prefer to use) - where the documents are created fine, but crashes when closing the document after printing

For Each sec As Aspose.Word.Section In fromDoc.Sections
Dim newSec As Aspose.Word.Section = toDoc.Sections(0).Clone

I understand your point about the floating images, but even with all the images removed and everything removed from headers etc the problem still occurs.

Any ideas?
I’ve tried ripping the docs to shreds and rebuild them, but the problem persists…

Thanks, please check back in 1-2 days, I think we will find the real cause of the problem.

I found out that you don’t even have to do merging to cause this crash on close after printing. You can just open and save one of your files using Aspose.Word, open in MS Word, print and close and it will crash. I also found that even if I delete all content from the file and open/save using Aspose.Word, it will still do the same crash.

I was not able to figure out what is really happening, this is beyond my understanding of DOC format at the moment. But I created a new document in MS Word, set the same page size and margins and copied your document (taking care to exclude the very last paragraph mark) and this document works just fine with Aspose.Word. I’ve only done this for one of your documents and its attached here. Sorry there is no other way for now, you will need to the same for other documents.