ThinkPHP Word添加水印
1.添加类库
omposer require phpoffice/phpword --ignore-platform-reqs
2.调用类库
$name = explode('.',$attachment->url); $t = $name[1]; $p = $name[0]; if($t=='docx'){ $PhpWord = IOFactory::load('/www/public'.$attachment->url); $section = $PhpWord->getSection(0); $header = $section->addHeader(); $header->addWatermark('/www/public/assets/img/water.png',array('height'=>1120/1.2,'width'=>790/1.2,'marginTop'=>-36,'marginLeft'=>-80,'posHorizontal'=>'absolute','posVertical'=>'absolute')); if($t=='docx'){ $s = 'Word2007'; }else{ $s = 'Word2007'; } $newp = $p.'w.'.$t; $objWriter = IOFactory::createWriter($PhpWord,$s); $objWriter->save('/www/public/'.$newp); }