Manh
Manh

Reputation: 123

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 \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!

Upvotes: 2

Views: 2888

Answers (1)

Saud
Saud

Reputation: 878

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

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

Upvotes: 4

Related Questions