如何在 phpword 中更改纸张大小?
我想要将纸张尺寸更改为 Legal 纸张(8.5 英寸 x 14 英寸)。我在文档中找不到该选项。我不确定如何应用该规则,并且文档中似乎没有与此相关的“纸张”或“大小”。
( https://phpword.readthedocs.io/en/latest/ )
有人知道是否可以在文档上设置所需的纸张尺寸吗?
最佳答案
默认情况下,section
元素在 style
数组中具有 orientation
属性。它设置为横向或纵向,这些是页面宽度和高度的默认值。但是,您可以按照自己的意愿设置它们。
orientation: Page orientation (portrait, which is default, or landscape).
pageSizeH. Page height in twip. Implicitly defined by orientation option. Any changes are discouraged.
pageSizeW. Page width in twip. Implicitly defined by orientation option. Any changes are discouraged.
这是它的链接:
https://phpword.readthedocs.io/en/latest/styles.html
现在,这是我如何在代码中使用它以使其正常工作的示例:
<?php
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection([
'pageSizeH' => \PhpOffice\PhpWord\Shared\Converter::inchToTwip(11),
'pageSizeW' => \PhpOffice\PhpWord\Shared\Converter::inchToTwip(8.5)
]);
转换器类中有静态方法来计算“Twip”单位,这很有帮助。
关于php - 如何在 PHPWord 中更改纸张大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43189689/