none
How can I add footers to sections

    Question

  • I'm have a docx template to which I want to insert some text. I also need different footers so I'm adding sections as well. The template contains two section changes (i.e. 3 pages) and no footers or footer references. The first and last pages must stay as they are, and I'm adding text to the middle page. I add a footer part and a footer reference to the first section break in order to set add a footer to the middle page. This will also apply the newly created footer part to the last so page. To prevent this, I create an empty footer part and apply that to the w:body/w:sectPr node. This works just fine. The problems start if I add another section in the middle. Now the first page contains the footer that should be on the middle section, and an empty footer is visible if I open the doc in Word. This even though the middle section is referencing the correct footer. I'm failing to understand how footers are referenced and rendered.

    Here's the original template. (I've omitted namespaces and rsids.)

    <w:document>
      <w:body>
        <w:p >
          <w:pPr>
            <w:sectPr>
              <w:pgSz w:w="4536" w:h="6804" w:code="11" />
              <w:pgMar w:top="567" w:right="0" w:bottom="0" w:left="0" w:header="0" w:footer="0" w:gutter="0" />
              <w:cols w:space="708" />
              <w:docGrid w:linePitch="360" />
            </w:sectPr>
          </w:pPr>
        </w:p>
        <w:p>
          <w:bookmarkStart w:name="BM_Main_start" w:id="0" />
          <w:bookmarkEnd w:id="0" />
          <w:pPr>
            <w:sectPr>
              <w:pgSz w:w="4536" w:h="6804" w:code="11" />
              <w:pgMar w:top="567" w:right="0" w:bottom="0" w:left="0" w:header="0" w:footer="0" w:gutter="0" />
              <w:cols w:space="708" />
              <w:docGrid w:linePitch="360" />
            </w:sectPr>
          </w:pPr>
        </w:p>
        <w:sectPr>
          <w:pgSz w:w="4536" w:h="6804" w:code="11" />
          <w:pgMar w:top="567" w:right="0" w:bottom="0" w:left="0" w:header="0" w:footer="0" w:gutter="0" />
          <w:cols w:space="708" />
          <w:docGrid w:linePitch="360" />
        </w:sectPr>
      </w:body>
    </w:document>

    And here's the result.

    <w:ftr>
      <w:p>
        <w:r>
          <w:t>My Footer</w:t>
        </w:r>
      </w:p>
    </w:ftr>

    <w:ftr>
      <w:p />
    </w:ftr>

    ...

    <w:document>
      <w:body>
        <w:p>
          <w:pPr>
            <w:sectPr>
              <w:pgSz w:w="4536" w:h="6804" w:code="11" />
              <w:pgMar w:top="567" w:right="0" w:bottom="0" w:left="0" w:header="0" w:footer="0" w:gutter="0" />
              <w:cols w:space="708" />
              <w:docGrid w:linePitch="360" />
              <w:footerReference w:type="default" r:id="Rf9cbaad4d24941ab" />
            </w:sectPr>
          </w:pPr>
        </w:p>
        <w:p>
          <w:bookmarkStart w:name="BM_Main_start" w:id="0" />
          <w:bookmarkEnd w:id="0" />
          <w:pPr>
            <w:pStyle w:val="CenterTitle" />
            <w:sectPr>
              <w:pgSz w:w="4536" w:h="6804" w:code="11" />
              <w:pgMar w:top="567" w:right="0" w:bottom="0" w:left="0" w:header="0" w:footer="0" w:gutter="0" />
              <w:cols w:space="708" />
              <w:docGrid w:linePitch="360" />
              <w:footerReference w:type="default" r:id="Rd3ce48abd14d42cd" />
            </w:sectPr>
          </w:pPr>
          <w:r>
            <w:t xml:space="preserve">Some text.</w:t>
          </w:r>
        </w:p>
        <w:p>
          <w:pPr>
            <w:pStyle w:val="CenterTitle" />
          </w:pPr>
          <w:r>
            <w:t xml:space="preserve">Some more text.</w:t>
          </w:r>
        </w:p>
        <w:sectPr>
          <w:pgSz w:w="4536" w:h="6804" w:code="11" />
          <w:pgMar w:top="567" w:right="0" w:bottom="0" w:left="0" w:header="0" w:footer="0" w:gutter="0" />
          <w:cols w:space="708" />
          <w:docGrid w:linePitch="360" />
          <w:footerReference w:type="default" r:id="Rd3ce48abd14d42cd" />
        </w:sectPr>
      </w:body>
    </w:document>

    Tuesday, February 26, 2013 2:40 PM

All replies

  • Wednesday, February 27, 2013 1:40 AM
    Moderator
  • Nope. Didn't help at all. I know how to create the footers. The problem is they don't behave as expected when viewed in Word. Looking at the XML I have the correct footer reference in the second section, but Word doesn't display the correct footer.
    Wednesday, February 27, 2013 6:49 AM
  • Hi Rubio

    I'm not certain I'm following everything but...

    << I add a footer part and a footer reference to the first section break in order to set add a footer to the middle page>>

    Headers and footers need to be specified in the section break following the section's text, not before. So if you need a footer for Section 2 you should be adding the reference in the second section break, not the first.


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, March 15, 2013 5:36 PM
    Moderator