Import paragraphs from a document to another one keeping the source formatting

Hi,

according to the code found in the forum, I tried to import a document into another one keeping the source style (see the code below).

The problem is that, even if the imported paragraphs are linked to the original styles and those styles look correctly imported in the new document, I lose the original style (I see multiple spaces between the lines, for instance)

I attach the source, destination and resulting docs

Regards, Roberto

private static Node Import1(Document dstDoc, Document innerDoc, Node insertAfterNode)
{
    NodeImporter importer = new NodeImporter(innerDoc, dstDoc, ImportFormatMode.KeepSourceFormatting);
 
    // We will be inserting into the parent of the destination paragraph.
    CompositeNode dstStory = insertAfterNode.ParentNode;
    // Loop through all sections in the source document.
    foreach (Section srcSection in innerDoc.Sections)
    {
        // Loop through all block level nodes (paragraphs and tables) in the body of the section.
        foreach (Node srcNode in srcSection.Body)
        {
            // Do not insert node if it is a last empty paragarph in the section.
            Paragraph para = srcNode as Paragraph;
            var oStyle = para.ParagraphFormat.Style;
 
            if ((para != null) && para.IsEndOfSection && !para.HasChildNodes)
                break;
 
            // This creates a clone of the node, suitable for insertion into the destination document.
            Node newNode = importer.ImportNode(srcNode, true);
 
            // Insert new node after the reference node.
            dstStory.InsertAfter(newNode, insertAfterNode);
            insertAfterNode = newNode;
        }
    }
    return insertAfterNode;
}

Hi

Thanks for your request. The problem occurs because your document have different “default formatting”. You can find the detailed explanation of this problem in the following thread:
https://forum.aspose.com/t/65084
Best regards,