PHPWORD页脚文本对齐问题

问题描述 投票:0回答:1

我正在使用phpword生成Word文件。页脚有问题。在页脚中,我有页码和文本机密文档。页码必须左对齐,机密文档必须右对齐。我尝试了以下脚本,但文本和页码均仅左对齐。

$phpword_object = new PHPWord();
$section = $phpword_object->createSection();

$footer = $section->createFooter();
$footer->addPreserveText('Page {PAGE} of {NUMPAGES}.',     
array(
    'align' => 'end',
    'positioning' => 'absolute'
));

$text = 'Confidential Document';

$footer->addPreserveText( $text,
    array(
        'align' => 'start',
        'positioning' => 'absolute'
    ));
php phpword
1个回答
0
投票

个人而言,我将使用一个简单的右对齐选项卡来完成此操作。无论是用代码形式还是在您面前的Word中打开docx文件时,都更容易理解。

因此,假设您在A4页面的两边都留有2.5cm的边距,那么您可以得到16cm的宽阔区域,因此将标签页设置为16cm,类似这样的代码(此代码有效-我刚刚尝试过:)]

$phpWord->addParagraphStyle('footer_paragraph', array('tabs' => array(new \PhpOffice\PhpWord\Style\Tab('right', \PhpOffice\PhpWord\Shared\Converter::cmToTwip(16)))));

$footer = $section->addFooter();

$footer->addPreserveText('Page {PAGE} of {SECTIONPAGES}' . "\u{0009}Confidential Document", 'your_own_font_style', 'footer_paragraph');

© www.soinside.com 2019 - 2024. All rights reserved.