Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Section page numbering #440

Closed
valimaties opened this issue Aug 23, 2022 · 10 comments
Closed

Section page numbering #440

valimaties opened this issue Aug 23, 2022 · 10 comments

Comments

@valimaties
Copy link

valimaties commented Aug 23, 2022

Hi.
I found here an issue which has some explanation, but it is not working.

I have a document which must be split in multiple sections. How do I get "Page x of n" for each section?
For example, I have a Section with 5 pages and another one with 8 pages. I want for each section the total number of pages. Currently, AppendPageCount() will get all pages from document.

I use the following code:

Formatting f = new();
var culture = new CultureInfo("ro-RO");
f.Language = culture;
sec.AddFooters();
Footer footerOdd = sec.Footers.Odd;
var pf = footerOdd.InsertParagraph();
pf.Append("Pag. ", f).Font("Arial").FontSize(8d)
    .AppendPageNumber(PageNumberFormat.normal).Font("Arial").FontSize(8d)
    .Append(" din ", f).Font("Arial").FontSize(8d)
    .AppendPageCount(PageNumberFormat.normal).Font("Arial").FontSize(8d).Alignment = Alignment.center;

I set already sec.PageNumberType.PageNumberStart = 1; property for the section, and indeed the section starts with 1, but the total number of pages returned by AppendPageCount() returns 13, not 5 and 8

EDIT:
I've found this example for Word Automation to count pages of each section. But something is missing here, I didn't found Section.Range.Information(3) //wdActiveEndPageNumber=3

@valimaties valimaties changed the title Section page numeration Section page numbering Aug 23, 2022
@XceedBoucherS
Copy link
Collaborator

Hi,

thank you for reporting this.
The Paragraph.AppendPageCount() method must be adapt to use the field "SECTIONPAGES" for your situation in order to count the pages from a section instead of for the whole document.
This will be possible in v2.4 with a new parameter in method Paragraph.AppendPageCount()/InsertPageCount().
Thank you

@valimaties
Copy link
Author

Hi @XceedBoucherS .
Or a new method like AppendSectionPagesCount().

PS: About AppendPageCount() method, it has an issue: when the footer is not selected the pages are count correctly, but when I double click the footer, the value returned by AppendPageCount() it increese itself by 1. I don't know why. I will make some more tests tommorrow, and probably, if I encounter again the situation, I will make a small video.

Thanks

@valimaties
Copy link
Author

Hi @XceedBoucherS .
I tried to replace manually in "footer.xml" (there was two files, footer3 and footer6), the value of fldSimple from NUMPAGES to SECTIONPAGES and it's working, it counts pages correctly.
sectionpages

I've created a new branch in my forked solution and I've duplicate the AppendPageCount method in Paragraph class, renamed to AppendSectionPageCount and modified with this SECTIONPAGES property, and used it in my project, and seems to work.

I've created a PR for this. If you don't want to merge it, or it has some issues, please tell me. Right now, I'm using my version, as long as pages are counting ok with this new method.
BTW: thanks for the tip with SECTIONPAGES :)

@XceedBoucherS
Copy link
Collaborator

Hi @valimaties ,
No problem for the help.
I will not merge your PR because we do not merge them. Instead, we update the code with all new features and fixes about every 3-4 months. This option will be available in v2.4 of DocX.
Thank you for pointing this out.

@valimaties
Copy link
Author

Ok.
Till then I will use my forked solution. Could you tell me if you will use the same method name, or I have to modify in my code when it will be released?

@XceedBoucherS
Copy link
Collaborator

Hi,
Unless we do a change before the release (for any reason), we are planning to use the same methods (InsertPageCount and AppendPageCount) and pass a new bool parameter to use the sectionPageCount or the documentPageCount(the default value). This way, we won't create new methods in the API for almost the same thing.

@valimaties
Copy link
Author

valimaties commented Aug 25, 2022

Thanks, in this case I will modify my branch as well, to fit your idea, till your release time.
Regards.

PS: I modified my branch, removing my method and modified those two InsertPageCount() and AppendPageCount().

@valimaties
Copy link
Author

valimaties commented Sep 27, 2022

I was expecting for this to be updated too in the last version... Seems I have to use my branch till the implementation of the PR related to this issue 😌

@XceedBoucherS
Copy link
Collaborator

Hi valimaties,
Yes, it is part of v2.4, but v2.3 was just released. Next release will have it, I promise !
Thank you

@valimaties
Copy link
Author

@XceedBoucherS , thanks for the new update which closes this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants