Hello,
I have two documents with the following layout:
1. A target document that is setup in two column layout.
2. A source document that is setup in single column layout, text is centered, and enclosed in section breaks.
I’m using the sample code below to insert the source document in a bookmarked location in the target document. However, upon inserting the source document, the section breaks are getting lost and therefore, the source document takes the page layout of the target document which is in two columns.
Is there a way to preserve the section breaks of the source document when inserting into the target document?
CODE:
’’’
‘’’ Inserts content of the external document after the specified node.
‘’’ Section breaks and section formatting of the inserted document are ignored.
‘’’
‘’’ <param name=“insertAfterNode”>Node in the destination document after which the content
‘’’ should be inserted. This node should be a block level node (paragraph or table).
‘’’ <param name=“srcDoc”>The document to insert.
Private Shared Sub InsertDocument(ByVal insertAfterNode As Node, ByVal srcDoc As Document)
’ Make sure that the node is either a paragraph or table.
If ((Not insertAfterNode.NodeType.Equals(NodeType.Paragraph))) And ((Not insertAfterNode.NodeType.Equals(NodeType.Table))) Then
Throw New ArgumentException(“The destination node should be either a paragraph or table.”)
End If' We will be inserting into the parent of the destination paragraph. Dim dstStory As CompositeNode = insertAfterNode.ParentNode ' This object will be translating styles and lists during the <span class="code-keyword">import</span>. Dim importer As New NodeImporter(srcDoc, insertAfterNode.Document, ImportFormatMode.KeepSourceFormatting) ' Loop through all sections in the source document. For Each srcSection As Section In srcDoc.Sections ' Loop through all block level nodes (paragraphs and tables) in the body of the section. For Each srcNode As Node In srcSection.Body ' Let's skip the node <span class="code-keyword">if</span> it is a last empty paragraph in a section. If srcNode.NodeType.Equals(NodeType.Paragraph) Then Dim para As Paragraph = CType(srcNode, Paragraph) If para.IsEndOfSection AndAlso (Not para.HasChildNodes) Then Continue For End If End If ' This creates a clone of the node, suitable <span class="code-keyword">for</span> insertion into the destination document. Dim newNode As Node = importer.ImportNode(srcNode, True) ' Insert <span class="code-keyword">new</span> node after the reference node. dstStory.InsertAfter(newNode, insertAfterNode) insertAfterNode = newNode Next srcNode Next srcSection
End Sub