首页 > 解决方案 > PHPOffice/PHPWord - 如何设置横向纸张大小

问题描述

我确实关注了这篇文章:如何在 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');

?>

它将使用信纸和纵向布局创建文件

我改成这样:

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

它生成的文件具有横向布局,但为A4纸大小。

如何生成具有 Letter 大小 + 横向布局的文件?

谢谢!

标签: phpphpwordphpoffice

解决方案


在具有宽度和高度的数组中插入方向键:

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

推荐阅读