Replies: 4   Views: 2300
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 kobbe  · 10-12-2018 - 13:28

Hello! Am using template and need a way to find out margins (top, right, bottom and left). How can I do it? I only find how to set it using modifyPageLayout... but I do not want to set it since it will be different depending on template. :)

Posted by kobbe  · 11-12-2018 - 08:18

Thank you for fast reply.

I am not understandig what type to use.

$queryInfo = $docx->getDocxPathQueryInfo(null);


array(3) {
  object(DOMNodeList)#271 (1) {
  string(15) "//w:body/*[1=1]"

What parameters should I use? :o

Posted by admin  · 11-12-2018 - 08:50

Deleted by admin · 11-12-2018 - 08:55

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):