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. :)
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. :)
Hello,
Using the following method of DOCXPath:
https://www.phpdocx.com/api-documentation/docx-path/get-docx-path-query-info
You can query by section an get its information from the tag w:pgMar of the elements key of the returned array. Please check the included samples to understand how to use this method.
Regards.
Thank you for fast reply.
I am not understandig what type to use.
$queryInfo = $docx->getDocxPathQueryInfo(null);
var_dump($queryInfo);
Result:
array(3) {
["elements"]=>
object(DOMNodeList)#271 (1) {
["length"]=>
int(1)
}
["length"]=>
int(1)
["query"]=>
string(15) "//w:body/*[1=1]"
}
What parameters should I use? :o
Hello,
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 (https://www.phpdocx.com/api-documentation/docxutilities/indexer-parse-word-documents-with-PHP).
We have generated a code to get that information from any existing DOCX:
<?php
require_once 'classes/CreateDocx.php';
$docxStructure = new DOCXStructure();
$docxStructure->parseDocx('template.docx');
$documentDOM = new DOMDocument();
$optionEntityLoader = libxml_disable_entity_loader(true);
$documentDOM->loadXML($docxStructure->getContent('word/document.xml'));
libxml_disable_entity_loader($optionEntityLoader);
$documentXpath = new DOMXPath($documentDOM);
$documentXpath->registerNamespace('w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
$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): http://officeopenxml.com/WPSectionPgMar.php
Regards.