xceedsoftware / DocX

Fast and easy to use .NET library that creates or modifies Microsoft Word files without installing Word.
Other
1.78k stars 475 forks source link

Paragraph AppendPageNumber() starting number is wrong for a new section #450

Open valimaties opened 1 year ago

valimaties commented 1 year ago

Hi. I have two issues about Section's page counting. I don't know if these are issues from my MS Office 2019 or they are from this library:

  1. After I open the created document, the total amount of pages for a section is not refreshed correctly, and it displays different total numbers while navigating thru pages. It refreshes only after some pages are displayed. For example, if the first section have 11 pages, when I open the document it shows "Pg. 1 of 4", I scroll to the next page and it displays "Pg. 2 of 5", I continue to scroll to the next page and it displays "Pg. 3 of 11". Right now, if I scroll up to second or to the first page it display correctly "Pg 2 of 11" and "Pg 1 of 11".
  2. In a document with multiple sections, the starting number for section starts correctly for first section, which is 1, but from the second section, all sections starts with number 2.
XceedBoucherS commented 1 year ago

Hi,

for 2) Page Numbering, if you want each page number to start at 1 for each section of the document, you can do like that: ` var doc = DocX.Create( "test.docx" ); doc.InsertParagraph( "First Paragraph" );

  doc.InsertSectionPageBreak();

  doc.InsertParagraph( "Second Paragraph" ).InsertPageBreakAfterSelf();
  doc.InsertParagraph( "new Paragraph of second section" );

  doc.InsertSectionPageBreak();

  doc.InsertParagraph( "Third Paragraph" );

  foreach( var section in doc.Sections )
  {
    section.PageNumberType = new PageNumberType() { PageNumberStart = 1 };
  }
  doc.AddHeaders();
  doc.Headers.Odd.InsertParagraph( "Page " ).AppendPageNumber( PageNumberFormat.normal ).Append( " of " ).AppendPageCount( PageNumberFormat.normal, true );

  doc.Save();`

If you still have issues with page numbers, please send a sample showing the issue.

Thank you