php - 如何在 PHPWord 中更改纸张大小

标签 php phpword

如何在 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/

相关文章:

php - 将 PHP 代码实现为函数

php - PHP从单独的文件检查空值

Laravel 5 中的 PHPWord

joomla - 将 PHPWord 添加到 Joomla

cakephp - PHPWord 创建多个表

php - PHPWord中模板处理器的默认目录是什么?

php - 为什么 Apache 在没有扩展名的调用文件上执行 php 文件

php - 使用php搜索oracle数据库

php - mysql查询通过根据日期添加总和来从2个表中获取结果

phpword - PHPWord中如何合并单元格?或者每个表格行中有不同数量的单元格?