Skip to content
Advertisement

PHPOffice/PHPWord – How to setup paper size with landscape orientation

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

<?php

require_once 'vendor/autoload.php';

$phpword = new PhpOfficePhpWordPhpWord();

$paper = new PhpOfficePhpWordStylePaper();
$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!

Advertisement

Answer

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

$section = $phpword->addSection(array(
    'pageSizeW' => $paper->getWidth(), 
    'pageSizeH' => $paper->getHeight(), 
    'orientation' => 'landscape'
));
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement