PHPOffice / PHPWord

A pure PHP library for reading and writing word processing documents
https://phpoffice.github.io/PHPWord/
Other
7.21k stars 2.68k forks source link

How to setup paper size with orientation #2027

Closed lamkute closed 3 months ago

lamkute commented 3 years ago

Hello, im trying to create a document in Letter paper size and Landscape orientation with this code. but it still give A4 size. Can anybody help? Thank you!

<?php
require_once 'vendor/autoload.php';
$paper = new \PhpOffice\PhpWord\Style\Paper();
$paper->setSize('Letter');  

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

$section = $phpword->addSection(array('orientation' => 'landscape'));
$section->addText("Hello World!");

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

?>
oleibman commented 3 years ago

This should work:

<?php
require_once 'vendor/autoload.php';

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

$section = $phpword->addSection();
$section->getStyle()
    ->setPaperSize('Letter')
    ->setLandscape()
;
$section->addText("Hello World!");

$phpword->save('./letter.docx', 'Word2007');
SarahTrees commented 3 months ago

Support question successfully answered. Sample code works. Issue can be marked as closed.