How to set margins for Header and footer

Nov 25, 2014 at 10:52 AM
Can anyone help to set margins for header and footer
Feb 17, 2016 at 9:10 PM
Brute force.
private void tweakIt(DocX document)
{
    XNamespace w = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
    var xml = document.Xml.Document;

    XElement body = xml.Root.Element(XName.Get("body", w.NamespaceName));
    XElement sectPr = body.Element(XName.Get("sectPr", w.NamespaceName));
    if (sectPr != null)
    {
        XElement pgMar = sectPr.Element(XName.Get("pgMar", w.NamespaceName));
        if (pgMar != null)
        {
            XAttribute header = pgMar.Attribute(XName.Get("header", w.NamespaceName));
            if (header != null)
            {
                header.SetValue(100);
            }
            XAttribute footer = pgMar.Attribute(XName.Get("footer", w.NamespaceName));
            if (footer != null)
            {
                footer.SetValue(100);
            }
        }
    }
}