We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Merge with KEEP_SOURCE_FORMATTING dropping source line spacing

I am finding that when appending a document using ImportFormatMode.KEEP_SOURCE_FORMATTING sometimes the source document will have its paragraph line spacing revert to Single spacing (from Multiple 1.15 in the source) at a seemingly random although consistent location in the merged document. Once the line spacing reverts to Single it remains reverted to Single for the remainder of the document. I’m using Aspose.Words for Java 13.8.0.0.
Attachments:
destination.docx
source.docx
merged.docx (the offending line where line spacing unexpectedly changes begins “2. Amendment of Contract.”)

Hi Tad,

Thanks for your inquiry. In your case, I suggest you please use the ImportFormatMode.USE_DESTINATION_STYLES when importing content from another document.

When using the USE_DESTINATION_STYLES option, if a matching style already exists in the destination document, the style is not copied and the imported nodes are updated to reference the existing style.

The drawback of using USE_DESTINATION_STYLES is that the imported text might look different in the destination document comparing to the source document. For example, the “Heading 1” style in the source document uses Arial 16pt font and the “Heading 1” style in the destination document uses Times New Roman 14pt font. When importing text of “Heading 1” style with no other direct formatting, it will appear as Times New Roman 14pt font in the destination document.

Using the KEEP_SOURCE_FORMATTING option allows to make sure the imported text looks in the destination document exactly like it was in the source document. If a matching style already exists in the destination document, the source style is copied and given a unique name by appending a suffix number to it, for example “Normal_0” or “Heading 1_5”.

The drawback of using KEEP_SOURCE_FORMATTING is that if you perform several imports, you could end up with many styles in the destination document and that could make using consistent style formatting in Microsoft Word difficult for this document. Please read following documentation links for your kind reference.
https://docs.aspose.com/words/java/insert-and-append-documents/

Tahir,
The description of KEEP_SOURCE_FORMATTING is really what I want, however USE_DESTINATION_STYLES does eliminate this issue.
Everything generally seems to work, probably because the documents we are merging more or less share the same styles. I did however see one issue with USE_DESTINATION_STYLES where the paragraph spacing in header/footers is being inherited from the destination document. If I swap the source and destination documents (and insert the source before the destination) it should probably fix that.
I still wonder if the issue I am seeing with KEEP_SOURCE_FORMATTING is a bug. I may continue to play around to see if I can find a work-around for that.
-Tad

Something that seems to be a factor in the line spacing issue is that my source document (in the example here) was also generated from a merge of probably 8 or 10 files using KEEP_SOURCE_FORMATTING. If instead I generate that document using USE_DESTINATION_STYLES and then generate the final document (in the example here) using KEEP_SOURCE_FORMATTING then everything seems to work.
So I suggest that maybe the observed line spacing issue/bug may be more likely to happen in situations where documents are being cumulatively merged.

Hi Tad,

Thanks for your inquiry. Please note that Aspose.Words mimics the same behavior as MS Word do. If you merged your document by using MS Word with ‘keep source formatting’, you will get the same output.

I have tested again the scenario and have managed to reproduce the same issue at my side while using old version of Aspose.Words (v 13.8.0). However, this issue has been fixed in latest version of Aspose.Words for Java 13.9.0. I would suggest you please upgrade to the latest version (v13.9.0) from here and let us know how it goes on your side.

I have used the following code example to test your issue and have attached the output Docx file with this post for your kind reference.

// The document that the content will be appended to.
Document dstDoc = new Document(MyDir + "destination.docx");
// The document to append.
Document srcDoc = new Document(MyDir + "source.docx");
// Append the source document to the destination document.
// Pass format mode to retain the original formatting of the source document when importing it.
dstDoc.appendDocument(srcDoc, ImportFormatMode.KEEP_SOURCE_FORMATTING);
// Save the document.
dstDoc.save(MyDir + "Out.docx");

Awsome!
Aspose.Words is an amazingly powerful tool. I am constantly impressed with how well it works considering the detail of capabilities it takes care of goes so far beyond simply reading/writing a document model.

Hi Tad,

Thanks for your feedback. It is nice to hear from you that your problem has been solved. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.

We finally got around to upgrading from v13.8. The issue with KEEP_SOURCE_FORMATTING was fixed as of v13.12. Thanks! Now if we can only get that version to work with Java Webstart, which I have posted as a separate issue.

Hi Tad,

It is nice to hear from you that you have found the solution of your issue. Please check my reply about your Webstart query from here.