Calculating the Footer height of a Docx by using the OpenXml SDK RRS feed

  • Question

  • I’m inserting an image into the body section at the place of a bookmark.

    But before inserting the image I want to calculate the maximum height that the image may have to insert it on that page.

    I calculate the height by substracting the TopMargin and BottomMargin from the pageHeight. But when the document has a Footer which is larger than the BottomMargin of the page I need to know the height of the footer.

    But the FooterMargin is NOT the real height of the footer, so my question:

    How can I calculate the real Footer Height from a docx (page) by using the OpenXml SDK?

    Thanks, Robin van Halen

    Friday, August 20, 2010 1:52 PM


  • Hello,

    Acording to the OpenXML SDK 2.0 Design Considerations,

    • Does not provide application behavior such as layout functionality in Word or recalculation, data refresh, or adjustment functionalities in Excel.

    It is not designed to be able to calculate the document content size and layout. The height of the footer information is also not exposed from the Open XML file content. So the objective is hard to achieved using the OpenXML SDK.

    A potential workaround would be using Word automation to do that. We can get information related to Footer by, the following codes,

    Sub Test()
    Application.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
    Debug.Print Application.Selection.HeaderFooter.Range.InlineShapes(1).Height
    End Sub

    But, whether and how this works depends on your detail requirment. However, that is off topic here. If you need more help on that approach, you can raise it in the Word for Developer forum.

    Have a nice day!


    Best regards,
    Ji Zhou - MSFT
    Microsoft Online Community Support


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Friday, August 27, 2010 3:48 AM