ms-wordopenxmlpage-numbering

How to change page number of a Word Docx


I have a generated word document (docx) and want to change the page number afterwards, in a way that it starts at number X. The page number is included in the footer of the word document. Where in the XML files do I need to apply this change?

I have changed a document to start at number 4 and looked at the XML code. The element <w:pgNumType w:start="4"/> was added. But if I only add this part manually to the XML, the document is broken.

document.xml content before adding "start with number 4":

        <w:sectPr w:rsidR="00C17A11" w:rsidRPr="00CD0C83" w:rsidSect="00A86D42">
            <w:headerReference r:id="rId8" w:type="even"/>
            <w:headerReference r:id="rId9" w:type="default"/>
            <w:footerReference r:id="rId10" w:type="even"/>
            <w:footerReference r:id="rId11" w:type="default"/>
            <w:headerReference r:id="rId12" w:type="first"/>
            <w:footerReference r:id="rId13" w:type="first"/>
            <w:pgSz w:h="16838" w:w="11906"/>
            <w:pgMar w:bottom="851" w:footer="567" w:gutter="0" w:header="851" w:left="1304" w:right="567" w:top="828"/>
            <w:cols w:space="708"/>
            <w:docGrid w:linePitch="360"/>
        </w:sectPr>

And after adding "start with number 4":

<w:sectPr w:rsidR="00C17A11" w:rsidRPr="00CD0C83" w:rsidSect="00CA253E">
  <w:headerReference w:type="default" r:id="rId8"/>
  <w:footerReference w:type="default" r:id="rId9"/>
  <w:pgSz w:w="11906" w:h="16838"/>
  <w:pgMar w:top="828" w:right="567" w:bottom="851" w:left="1304" w:header="851" w:footer="567" w:gutter="0"/>
  <w:pgNumType w:start="4"/>
  <w:cols w:space="708"/>
  <w:docGrid w:linePitch="360"/>
</w:sectPr>

Solution

  • As Josch mentioned you are doing everything right. There is nothing more to be added to the document.

    I have created an empty document with 4 pages in Word and then unpacked the contents of my .wordx file.

    Here is my document.xml file.

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex" xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 w15 w16se wp14">
        <w:body>
            <w:p w:rsidR="00ED7F18" w:rsidRDefault="00ED7F18">
                <w:r>
                    <w:br w:type="page"/>
                </w:r>
            </w:p>
            <w:p w:rsidR="00ED7F18" w:rsidRDefault="00ED7F18">
                <w:r>
                    <w:lastRenderedPageBreak/>
                    <w:br w:type="page"/>
                </w:r>
            </w:p>
            <w:p w:rsidR="00ED7F18" w:rsidRDefault="00ED7F18">
                <w:r>
                    <w:lastRenderedPageBreak/>
                    <w:br w:type="page"/>
                </w:r>
            </w:p>
            <w:p w:rsidR="0070592A" w:rsidRDefault="00ED7F18"/>
            <w:sectPr w:rsidR="0070592A" w:rsidSect="00ED7F18">
                <w:headerReference w:type="even" r:id="rId6"/>
                <w:headerReference w:type="default" r:id="rId7"/>
                <w:footerReference w:type="even" r:id="rId8"/>
                <w:footerReference w:type="default" r:id="rId9"/>
                <w:headerReference w:type="first" r:id="rId10"/>
                <w:footerReference w:type="first" r:id="rId11"/>
                <w:pgSz w:w="11906" w:h="16838"/>
                <w:pgMar w:top="1417" w:right="1417" w:bottom="1134" w:left="1417" w:header="708" w:footer="708" w:gutter="0"/>
                <w:pgNumType w:start="4"/>
                <w:cols w:space="708"/>
                <w:docGrid w:linePitch="360"/>
            </w:sectPr>
        </w:body>
    </w:document>
    

    Changing the following line

    <w:pgNumType w:start="4"/>
    

    to

    <w:pgNumType w:start="5"/>
    

    and then zipping back all the contents does the thing.

    You are probably zipping back the contents together with the folder they are in.

    Please make sure that the zip file has exactly the following folders/files.

    _rels
    docProps
    word
    [Content_Types].xml