The page number for the subsequent rows after adding the new row are still retaining their page number before the row addition

Hi Aspose team.
Sorry for bringing up this old post.

Aspose word .NET version: 22.11.0

I have re-use the logic suggested by Mr. Alexey Noskov in the previous comment, and it is working fine for adding new rows in an existing table.

The only issue I have is that all the page number for the subsequent rows after adding the new row, they are still retaining their page number before the row addition.

Illustration sample -
Condition:

  1. Page can only contain a maximum of 3 rows.
  2. Sample data of 3 pages.

Original -
page 1 have:

  1. row 1A
  2. row 1B
  3. row 1C

Page 2 have:

  1. row 2A
  2. row 2B
  3. row 2C

Page 3 have:

  1. row 3A
  2. row 3B
  3. row 3C

After adding new rows-
page 1 have:

  1. row 1A
  2. row 1B
  3. row 1C

Page 2 have:

  1. NewRow1
  2. row 2A
  3. row 2B

Page 3 have:

  1. row 2C - GetStartPageIndex on this row still show 2
  2. NewRow2 - This is added here instead
  3. row 3A

Page 4 have:

  1. row 3B - GetStartPageIndex on this row still show 3
  2. row 3C - GetStartPageIndex on this row still show 3

I have tried multiple ways to refresh the page number but none is working for me:

collector.Clear();
doc.UpdatePageLayout();
collector = new LayoutCollector(doc); - reinitializing LayoutCollector

Try getting page number from enumerator:

LayoutEnumerator enumerator = new LayoutEnumerator(doc);
enumerator.Current = collector.GetEntity(row);
var enumPageNumber = enumerator.PageIndex;

Can I check with you guys, is there something I am doing wrong here, or if a version upgrade could fix this?

Hope to hear from you guys soon.

Thanks.

Regards
Joseph

@josephwong Could you please attach your input, output and expected output documents here for testing? We will check the issue and provide you more information.

@alexey.noskov

Thanks for the prompt reply.
While trying to create a code to reproduce this for you, I have discovered the issue.

The UpdatePageLayout() function is malfunction as the doc.FontSettings for our document was not configured properly.

Once I fixed that, it is working fine now.

Thanks.

Regards
Joseph

@josephwong It is perfect that you managed to resolve the problem. Please feel free to ask in case of any further issues. We are always glad to help you.

@alexey.noskov
Just wanted to understand more on this.
The exact function that actually fixes the issue is:
doc.FontSettings.SetFontsSources(fontSources);

Originally this was done after document processing and generation, before we trigger doc.Save().

Can I get your help on the following questions?

  1. Can I know if there is any reason that UpdatePageLayout() and GetStartPageIndex() might malfunction due to doc.FontSettings.SetFontsSources(fontSources) not being triggered before we generate the document?
  2. Is it recommended to always SetFontsSources() before we perform any document generation process?

It would be helpful, if you can send me any aspose forum threads that is related to this as well.

Thanks.

@josephwong

  1. When you call UpdatePageLayout, Aspose.Words builds document layout, to build it accurately the fonts used in the document are required. To use GetStartPageIndex Aspose.Words needs to build document layout, so the fonts are also required.

  2. Yes, if document processing includes document layout operations, such as updating fields, updating page layout, using LayoutCollector or LayoutEnumerator, saving to fixed page formats (PDF, XPS, Images etc), it is required to set the fonts sources before performing them.

1 Like