Difference between KeepSourceFormatting and UseDEstinationStyles

Hi,

In our application we copy content of one document to another. We deal with many documents.

while copying we use the following code

Section importedSection = (Section)((Document)e.MatchNode.Document).ImportNode(srcDoc.FirstSection, true, ImportFormatMode.KeepSourceFormatting);

If we use 'KeepSourceFormatting'as in above line it is working fine for few documents but for few spacing issues are coming.

Section importedSection = (Section)((Document)e.MatchNode.Document).ImportNode(srcDoc.FirstSection, true, ImportFormatMode.UseDestinationStyles);

If we use 'UseDestinationStyles' as in above line it is working fine for few documents but for few spacing issues are coming.

Kindly let me know when to use 'KeepSourceFormatting' and when to use 'UseDestinationStyles' ?

Is there any condition we can specify so that we can use both the conditions?

Kindly tell me which condition i can use such that it will work for all documents.

Hi there,


Thanks for your inquiry. Please note that Aspose.Words mimics the same behavior as MS Word does. The ImportFormatMode specifies how formatting is merged when importing content from another document.

When using the UseDestinationStyles 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 UseDestinationStyles 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 KeepSourceFormatting 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 KeepSourceFormatting 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.

Hope this answers your query. Please let us know if you have any more queries.