Page numbering when combining documents


#1

In the combining documents process, if I have page numbering set up, the page numbering keeps numbering throughout the entire document, instead of stopping for each individual document like it needs to. So a 22 page combined document will show 1 of 22, 2 of 22, etc… and what is needed is each document to have its own page numbering. So the first 2 pages are page 1 of 2, page 2 of 2, then there may be no page numbering. Then later in the document there might be 1 o 3, 2 of 3, etc… Can you tweak the code for this?


#2

You see there is actually two fields that can be used as total page count: {NUMPAGES} that represent total count of pages in the document and {SECTIONPAGES} which represent total count of pages in the section.

Number of the current page is represented by {PAGES} field, which can be restarted in any section of the document by using PageSetup.RestartPageNumbering Property.

So to retain the source documents numbering scheme in the combined document we can restart page numbering for the first section of every document that is being combined. To keep total page count we can substitute {NUMPAGES} field with {SECTIONPAGES} field in the combined document and if the source document has several sections we need to merge them into one.

The following code does this:

Dim section As Section = srcDoc.Sections(0)
Dim builder As DocumentBuilder = New DocumentBuilder(srcDoc)
For i as Integer = 1 To srcDoc.Sections.Count - 1
builder.MoveTo(section.Body.LastChild)
If srcDoc.Sections(i).PageSetup.SectionStart = SectionStart.NewPage Then
builder.InsertBreak(BreakType.PageBreak)
End If
section.AppendContent(srcDoc.Sections(i))
Next

section = CType(dstDoc.ImportNode(section, True, ImportFormatMode.UseDestinationStyles), Section)
dstDoc.AppendChild(section)

section.PageSetup.SectionStart = SectionStart.NewPage

Dim primaryHeader As HeaderFooter = section.HeadersFooters.HeaderFooterType.HeaderPrimary)
If Not primaryHeader Is Nothing Then
primaryHeader.IsLinkedToPrevious = False
End If
Dim primaryFooter As HeaderFooter = section.HeadersFooters(HeaderFooterType.HeaderPrimary)
If Not primaryFooter Is Nothing Then
primaryFooter.IsLinkedToPrevious = False
End If
For Each paragraph As Paragraph In section.GetChildNodes(NodeType.Paragraph, True)
paragraph.ParagraphFormat.WidowControl = True
Next paragraph

However if we look at your templates we can see that their structure is complicated by using multi-column sections here and there. If we merge these sections with single-column sections than we will lose the multi-column formatting.

So, in your case I don't see any way of retaining source page numbering scheme and keeping source formatting at the same time.

That is not an Aspose.Words limitation. That is a limitation of MS Word.