php - PHPWORD页脚文本对齐问题
问题描述
我正在使用 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'
));
解决方案
就个人而言,我会用一个简单的右对齐标签来做到这一点。它更容易理解,无论是在代码形式中,还是在你面前的 Word 中打开 docx 文件后。
所以,假设你有一个 A4 页面,两边有 2.5 厘米的边距,给你一个 16 厘米宽的区域,所以把标签放在 16 厘米处,像这样(这段代码有效 - 我刚刚试过):
$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');
推荐阅读
- python - Django - 使用 Celery 7 天后更新字段值
- json - 如何基于相等性检查在 Spark 中使用内部数组查询嵌套 json
- javascript - 如何一次为特定标签中的所有元素编写事件监听器?
- r - 如何根据是否具有先前值插入逻辑值?
- bluetooth-lowenergy - 蓝牙 LE _commands_ 的消息结构/语法是什么?
- git - 从损坏的标头恢复本地分支
- python - 看门狗函数的命令行参数
- ember.js - 选择文件后的操作
- ruby - 使用 Carrierwave 将图像从 png 转换为 jpg
- php - 在控制器 Magento 2 中获取当前产品信息?