【发布时间】:2017-07-27 06:56:27
【问题描述】:
我正在尝试在现有的 Word 文档上添加水印,但无法添加。有很多创建新文档的示例,然后根据您的需要对其进行编辑。但找不到任何教程来编辑预先存在的 word 文档。
以下是我的代码。提前致谢。
<?php
require_once '../PHPWord.php';
// New Word Document
$PHPWord = new PHPWord();
// New portrait section
$section = $PHPWord->createSection();
// Create header
$header = $section->createHeader();
// Add a watermark to the header
$header->addWatermark('_earth.jpg', array('marginTop'=>200, 'marginLeft'=>55));
$section->addText("Hello World");
// Save File
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter->save('Watermark.docx');
?>
【问题讨论】: