By default, section
element has the orientation
property in the style
array. It is set to landscape or portrait, and these are default values for the page width and height. However, you can set them how you want.
orientation: Page orientation (portrait, which is default, or landscape).
pageSizeH. Page height in twip. Implicitly defined by orientation option. Any changes are discouraged.
pageSizeW. Page width in twip. Implicitly defined by orientation option. Any changes are discouraged.
Here is a link to it:
https://phpword.readthedocs.io/en/latest/styles.html
Now, here is an example of how I used it in my code in order to make it work:
<?php
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection([
'pageSizeH' => \PhpOffice\PhpWord\Shared\Converter::inchToTwip(11),
'pageSizeW' => \PhpOffice\PhpWord\Shared\Converter::inchToTwip(8.5)
]);
You have the static method in the converter class to calculate the ''Twip'' unit, which is helpful.