Replies: 4   Views: 2328
Get margins from template?
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  · 11-12-2018 - 09:21


You need to query by section type. But it will only work if the template has more than one section.

We have moved the request to the dev team to add that information to the Indexer class (

We have generated a code to get that information from any existing DOCX:


require_once 'classes/CreateDocx.php';

$docxStructure = new DOCXStructure();

$documentDOM = new DOMDocument();
$optionEntityLoader = libxml_disable_entity_loader(true);

$documentXpath = new DOMXPath($documentDOM);
$documentXpath->registerNamespace('w', '');

$sectionEntries = $documentXpath->query('//w:sectPr/w:pgMar');

foreach ($sectionEntries as $sectionEntry) {
    echo 'Top:' . $sectionEntry->getAttribute('w:top') . PHP_EOL;
    echo 'Right: ' . $sectionEntry->getAttribute('w:right') . PHP_EOL;
    echo 'Left: ' . $sectionEntry->getAttribute('w:left') . PHP_EOL;
    echo 'Bottom: ' . $sectionEntry->getAttribute('w:bottom') . PHP_EOL;

The returned values are twips (Twentieths of a Point):