Reputation: 5299
In my Word document i adding new Section:
var defaultSection = mainPart.Document.Descendants<SectionProperties>().First();
var paragraph2 = new Paragraph();
var paragraphProperties2 = new ParagraphProperties();
var sectionProperties2 = defaultSection.Clone() as SectionProperties;
var sectionTypeCur = sectionProperties2.Descendants<SectionType>().FirstOrDefault();
sectionProperties2.RemoveChild(sectionTypeCur);
var sectionType2 = new SectionType() { Val = SectionMarkValues.NextPage };
var pageNumberType2 = new PageNumberType()
{
ChapterSeparator = defaultPageNumbering.ChapterSeparator,
ChapterStyle = defaultPageNumbering.ChapterStyle,
Format = defaultPageNumbering.Format,
Start = null
};
var pageNumberTypeCur = sectionProperties2.Descendants<PageNumberType>().FirstOrDefault();
sectionProperties2.RemoveChild(pageNumberTypeCur);
sectionProperties2.Append(pageNumberType2);
var titlePageCur2 = sectionProperties2.Descendants<TitlePage>().FirstOrDefault();
sectionProperties2.RemoveChild(titlePageCur2);
paragraphProperties2.Append(sectionProperties2);
paragraph2.Append(paragraphProperties2);
lastElementInFirstSection.InsertAfterSelf(paragraph2);
And see that in new section page numbering starts from default value. But i want to page numbering continious from the highest page number in the previous section.
How can i do it?
Upvotes: 1
Views: 445
Reputation: 5122
You need to use SectionMarkValues.Continuous
instead of Val = SectionMarkValues.NextPage
. Continuous doesn't go to the next page, so you need to put in a plain next page break too, probably.
Upvotes: 1