DocX icon indicating copy to clipboard operation
DocX copied to clipboard

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

Open valimaties opened this issue 2 years ago • 1 comments

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.

valimaties avatar Jan 26 '23 10:01 valimaties

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

XceedBoucherS avatar Feb 09 '23 20:02 XceedBoucherS