ExtractPages - when I use ExtractPages it breaks my numbering

Good day,

when I split the document into sections. I use the following code for this, it breaks the numbering in the document. Could you take a look at it for me?

Document docPR = new Document($"{path}4P003q.docx");

Document docClone = docPR.Clone();
docClone.Sections.Clear();
docPR.UpdatePageLayout();

ImportFormatOptions opt = new ImportFormatOptions() { KeepSourceNumbering = true };
for (int i = 0; i < docPR.PageCount; i++)
{
    Document page = docPR.ExtractPages(i, 1);
    docClone.AppendDocument(page, ImportFormatMode.UseDestinationStyles, opt);
}
docClone.Save($"{path}4P003qOut.docx");

Document docX = new Document(@"C:\Temp\Html_dif\3P002f.docx");

Thank you in advance

4P003q.docx (7.5 MB)

@benestom
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-26386

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

It looks like the problem is caused by KeepSourceNumbering if disable this option numbering in the output document is correct.

Document doc = new Document(@"C:\Temp\in.docx");

Document docClone = (Document)doc.Clone(false);
ImportFormatOptions opt = new ImportFormatOptions() { KeepSourceNumbering = false };
for (int i = 0; i < doc.PageCount; i++)
{
    Document page = doc.ExtractPages(i, 1);
    docClone.AppendDocument(page, ImportFormatMode.UseDestinationStyles, opt);
}

docClone.Save(@"C:\Temp\out.docx");

@benestom With Document.EnsureMinimum(), MergeDocuments() works as expected and the numbering is correct:

Document docPR = new Document("in.docx");

Document docClone = (Document )docPR.Clone(false);

// Add this as the resilience for NRE! 
docClone.EnsureMinimum();

for (int i = 0; i < docPR.PageCount; i++)
{
    Document page = docPR.ExtractPages(i, 1);
    docClone = Merger.Merge(new Document[] { docClone, page }, MergeFormatMode.KeepSourceLayout);
}
docClone.Save("out.docx");

Please try using the suggested code and let us know if the problem still persists.