2

I did follow this post: How to change paper size in PHPWord

<?php

require_once 'vendor/autoload.php';

$phpword = new \PhpOffice\PhpWord\PhpWord();

$paper = new \PhpOffice\PhpWord\Style\Paper();
$paper->setSize('Letter'); 

$section = $phpword->addSection(array('pageSizeW' => $paper->getWidth(), 'pageSizeH' => $paper->getHeight()));

$section->addText("Hello World!");

$phpword->save('./test.docx', 'Word2007');

?>

It will create file with Letter paper and Portrait layout

I change to this:

$section = $phpword->addSection(array('orientation' => 'landscape'));

It generated file with Landscape layout but is A4 paper size.

How to generate file with Letter size + Landscape layout?

Thank you!

Saud
  • 859
  • 1
  • 9
  • 23
Manh
  • 123
  • 11
  • 1
    Have you tried using like this: `$phpword->addSection(array('pageSizeW' => $paper->getWidth(), 'pageSizeH' => $paper->getHeight(), 'orientation' => 'landscape'));` – Saud Feb 24 '21 at 07:13
  • @Saud it worked. Thank you so much! – Manh Feb 24 '21 at 07:17
  • No problem, I'm posting it as an answer so that others can also benefit from it. – Saud Feb 24 '21 at 07:21

1 Answers1

4

Insert the orientation key in the array with width and height:

$section = $phpword->addSection(array(
    'pageSizeW' => $paper->getWidth(), 
    'pageSizeH' => $paper->getHeight(), 
    'orientation' => 'landscape'
));
Saud
  • 859
  • 1
  • 9
  • 23