Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Wed May 21, 2014 4:12 pm

Hello,

I have a Word template that already has page numbering setup and working.

I'm looping through a collection of data and for each iteration I'm loading a copy of the template and populating it.
Some of these will end up spanning multiple pages.

Once the above template has been generated and populated I then add it to a "master" Document to merge all the above documents together.

The issue I'm seeing is that the page numbers are counting ALL pages and not resetting for each iteration.

How would I reset the page counter using Spire Doc?

Thanks,
Jon

jchapman123
 
Posts: 7
Joined: Wed Apr 30, 2014 6:51 pm

Thu May 22, 2014 7:19 am

Dear Jon,

Thanks for your inquiry.
Please refer to the following code to reset page number.
Code: Select all
   Section.PageSetup.RestartPageNumbering = true;
            Section.PageSetup.PageStartingNumber = 1;


Best wishes,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Thu May 22, 2014 1:06 pm

Hi Amy,

Thanks for the quick reply!

This did reset the starting page number but did not change the total pages.

so now I have "2 of 34" instead of "2 of 2"

is there a way to also reset the total count of pages?

Thanks,
Jon

jchapman123
 
Posts: 7
Joined: Wed Apr 30, 2014 6:51 pm

Fri May 23, 2014 6:59 am

Dear Jon,

Please change FieldNumPages in your document to FieldSectionPages.
Share some code:

Code: Select all
foreach (Section sec in document.Sections)
            {
                foreach (DocumentObject obj in sec.HeadersFooters.Footer.ChildObjects)
                {
                    if (obj.DocumentObjectType == DocumentObjectType.StructureDocumentTag)
                    {
                        DocumentObject para = obj.ChildObjects[0];
                        foreach (DocumentObject item in para.ChildObjects)
                        {
                            if (item.DocumentObjectType == DocumentObjectType.Field)
                            {
                                if ((item as Field).Type == FieldType.FieldNumPages)
                                {
                                    (item as Field).Type = FieldType.FieldSectionPages;
                                }
                            }
                        }
                    }       
                }
            }


Please feel free to contact us if you have any problems.

Best wishes,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Fri May 23, 2014 11:32 am

How do I SET the FieldSectionPages value?

jchapman123
 
Posts: 7
Joined: Wed Apr 30, 2014 6:51 pm

Mon May 26, 2014 2:06 am

Dear Jon,

You just need to set the field type of page numbers to FieldSectionPages as the line (item as Field).Type = FieldType.FieldSectionPages;.
I attached my whole code and test documents, please kindly check it.

Please feel free to contact us if you have any problems.

Best wishes,
Amy
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Tue May 27, 2014 6:23 pm

Working great!

Thanks for the help Amy.

jchapman123
 
Posts: 7
Joined: Wed Apr 30, 2014 6:51 pm

Wed May 28, 2014 1:23 am

Dear Jon,

Thanks for your feedback.

Welcome to write to us for further problems.

Best wishes,
Amy
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.Doc