Here's a sample method which inserts 3 first pages of a source document to the specified node of a destination document:
///
/// Inserts content of the external document after the specified node.
///
/// Node in the destination document where the external document content should be inserted.
/// Document to insert.
public void InsertDocument(Node node, Document doc)
{
CompositeNode parentNode = node.ParentNode;
while (true)
{
if (parentNode == null)
throw new Exception("Document cannot be inserted after the specified node.");
if (parentNode is Story || parentNode is Cell || parentNode is Shape)
break;
node = parentNode;
parentNode = node.ParentNode;
}
int index = node.ParentNode.ChildNodes.IndexOf(node);
Document dstDoc = node.Document;
Section insertedSection;
foreach (Section section in doc.Sections)
{
insertedSection = (Section)dstDoc.ImportNode(section, true, ImportFormatMode.KeepSourceFormatting);
foreach (Node insertedNode in insertedSection.Body.ChildNodes)
{
// Do not insert node if it is a last empty paragarph in the section.
if (insertedNode is Paragraph && insertedNode == section.Body.LastChild && insertedNode.ToTxt().Equals(string.Empty))
break;
if (insertedNode is Paragraph)
{
Paragraph para = (Paragraph)insertedNode;
if ((para.Runs.Count > 0) && (para.Runs[0].Text.StartsWith(ControlChar.PageBreak)))
return;
}
parentNode.ChildNodes.Insert(++index, insertedNode.Clone(true));
}
}
}
Basically, this is a modified version of the document importing algorithm posted in one of the recent threads that halts once an explicit page break is encountered at the beginning of a paragraph. I'm also attaching a sample source document with an explicit page break at the end of the third page.