DocX icon indicating copy to clipboard operation
DocX copied to clipboard

Section page numbering

Open valimaties opened this issue 3 years ago • 7 comments

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 avatar Aug 23 '22 09:08 valimaties

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

XceedBoucherS avatar Aug 23 '22 19:08 XceedBoucherS

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 avatar Aug 23 '22 20:08 valimaties

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 :)

valimaties avatar Aug 24 '22 07:08 valimaties

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.

XceedBoucherS avatar Aug 24 '22 12:08 XceedBoucherS

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?

valimaties avatar Aug 25 '22 07:08 valimaties

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.

XceedBoucherS avatar Aug 25 '22 11:08 XceedBoucherS

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 avatar Aug 25 '22 11:08 valimaties

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 😌

valimaties avatar Sep 27 '22 11:09 valimaties

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

XceedBoucherS avatar Sep 27 '22 11:09 XceedBoucherS

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

valimaties avatar Dec 08 '22 10:12 valimaties