【问题标题】:PHPWord Footer PositionPHPWord 页脚位置
【发布时间】:2019-07-29 11:00:34
【问题描述】:

有谁知道是否可以使用 PHPWord 重新定位(或设置高度)页脚?

我有一个完全符合文本要求的页脚。

$footer = $section->addFooter();
$textrun = $footer->addTextRun();
$textrun->addText('My Footer Text');

但是,我想要实现的是:

降低页脚高度或设置与页面底部的距离。

Word365 中有一个选项叫“底部页脚”,旧版本的 Word 中也有类似的选项。

我尝试过调整页边距,但这些页边距似乎与页脚(和页眉)的位置是分开的。

【问题讨论】:

    标签: position footer margins phpword phpoffice


    【解决方案1】:

    通过查看 GitHub 存储库,我设法找到了解决方案。

    这个提交提供了一个解决方案:Added support for page header & page footer height

    您可以在创建包含页眉和页脚的部分时传递属性“headerHeight”和“footerHeight”。

    // Adding an empty Section to the document...
    $section = $this->_phpWord->addSection(array(
                            'headerHeight' => 300,
                            'footerHeight' => 50)
                        );
    
    $footer = $section->addFooter();
    $textrun = $footer->addTextRun();
    $textrun->addText('My Footer Text');
    

    还有一些公共方法可以在您创建完部分后设置这些值,它们是:setFooterHeight() 和 setHeaderHeight()。

    $section->setHeaderHeight(300);
    $section->setFooterHeight(50);
    

    【讨论】:

    • 在 addSection() 中将值设置为参数有效。如果已在 addSection 中指定参数(任何类型的),则稍后设置页眉/页脚高度不起作用。 – PHPWord v0.16.0(2018 年 12 月 30 日)–
    猜你喜欢
    • 2020-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-05
    • 1970-01-01
    • 2015-08-24
    相关资源
    最近更新 更多