How to add/set images on PHPOffice/PHPWord Template?
Following code is the updated version of the one from TotPeRo (thanks again for your code!), for last phpOffice (0.11) that has evolved a little
/**
* Set a new image
*
* @param string $search
* @param string $replace
*/
public function setImageValue($search, $replace)
{
// Sanity check
if (!file_exists($replace))
{
return;
}
// Delete current image
$this->zipClass->deleteName('word/media/' . $search);
// Add a new one
$this->zipClass->addFile($replace, 'word/media/' . $search);
}
Can be called with:$document->setImageValue('image1.jpg', 'my_image.jpg');
How to add image in the headersection using PHPWORD?
Can you post more of the code please?
Meanwhile, I think the createHeader();
function has been deprecated. The addHeader();
function worked fine for me. You could give it a try too. Also, consider bringing down the width of the cells being created. Of course, these are wild guesses but who knows one of them might get things working for you. ;-)
Good Luck!
Edit 2020/02/12:
createHeader method is nowadays deprecated, use addHeader instead.
$header = $section->addHeader();
Reference: https://phpword.readthedocs.io/en/latest/containers.html#headers
Related Topics
How to Access My Wamp Server on Another Local Computer
How to Get the Root Url of the Site
Check If Youtube and Vimeo-Clips Are Valid
How to Remove All Dtddwrappers and Labels on Zend Form Elements
How to Get the Absolute Path to the Public_HTML Folder
Echo 'String' While Every Long Loop Iteration (Flush() Not Working)
Remove Namespace from Xml Using PHP
How to Reference a Column Other Than 'Id' for a Joincolumn
Why Is Object Oriented PHP with MySQLi Better Than the Procedural Approach
PHP Readfile() Causing Corrupt File Downloads
Adding an Admin Page on Opencart Version 2
PHP Explode Array Then Loop Through Values and Output to Variable
Built in Support for Sets in PHP
Changes to Upload_Max_Filesize in Ubuntu PHP.Ini Will Not Take Effect
What Is an Appropriate Content-Type Header for JavaScript Files