Forum


Replies: 1   Views: 1434
Add different margins for header & document content
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by admin  · 03-01-2022 - 12:09

Hello,

modifyPageLayout allows setting the following margins:

marginTop int     Top margin in twips (twentieths of a point).
marginRight     int     Right margin in twips (twentieths of a point).
marginBottom    int     Bottom margin in twips (twentieths of a point).
marginLeft      int     Left margin in twips (twentieths of a point).
marginHeader    int     Header margins in twips (twentieths of a point).
marginFooter    int     Footer margins in twips (twentieths of a point).

And also the page gutter and other options.

Page margins work as the following documentation details (http://officeopenxml.com/WPSectionPgMar.php):

bottom    
Specifies the distance (in twips or twentieths of a point) between the bottom of the text margin and the bottom of the page. The text is placed at the greater of the value of this attribute and the extent of the footer text. A negative value indicates that the content should be measured from the bottom of the page regardless of the footer, and so will overlap the footer. For example, <w:pgMar w:header="-720" w:bottom="1440" .../> means that the footer must start one inch from the bottom of the page and the main document text must start a half inch from the bottom of the page. In this case, the text and footer overlap since bottom is negative.

footer  
Specifies the distance (in twips or twentieths of a point) from the bottom edge of the page to the bottom edge of the footer.

gutter  
Specifies the page gutter (the extra space added to the margin, typically to account for binding).

header  
Specifies the distance (in twips or twentieths of a point) from the top edge of the page to the top edge of the header.

left    
Specifies the distance (in twips or twentieths of a point) from the left edge of the page to the left edge of the text.

right   
Specifies the distance (in twips or twentieths of a point) from the right edge of the page to the right edge of the text.

top     
Specifies the distance (in twips or twentieths of a point) from the top edge of the page to the top edge of the text. The text is placed at the greater of the value of this attribute and the extent of the header text. A negative value indicates that the contents of the document text should be measured from the top of the page regardless of the header, and will overlap the header text.

For example you can apply a 0 value to header margin (although MS Word adds a minimum space) and other value to the top margin:

$docx->modifyPageLayout(
        'A4',
        array(
            'marginHeader' => 0,
            'marginTop' => 2000,
        )
    );

Regards.