Forum


Replies: 1   Views: 2060
Image not displaying in footer (only if not added to text array)
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by pwctechnicalsecurity  · 17-08-2019 - 15:18

Could you help me with the following? I am trying to achieve that the logo is displaying in the footer. In the first snippet, it works (but produces an unwanted new paragraph (between the image and the page indicator and document title), which messes up the design). However, if I try to add the image to the $text array, as outlined in the second snippet, the image is not loading. I have indicated the changes in the second snippet. Any suggestions?

// ----------------------------------------------------------------------------
// Create the TOC
// ----------------------------------------------------------------------------

$toc = new CreateDocx();

$toc->modifyPageLayout('A4', array(
    'marginTop' => '1077.2',
    'marginRight' => '720',
    'marginBottom' => '1320.94',
    'marginLeft' => '2517.2'
));

$header = new WordFragment($letter, 'defaultHeader');
$header->addText('');
$toc->addHeader(array('default' => $header));

$imageOptions = array(
    'src' => 'images/footer.png', // $this->getParameter('kernel.project_dir') . '/public/images/footer.png',
    'height' => 163,
    'width' =>  215,
    'relativeToHorizontal' => 'page',
    'relativeToVertical' => 'page',
    'horizontalOffset' => 459740,
    'verticalOffset' => 9558020,
    'textWrap' => 3
);

$footer = new WordFragment($toc, 'defaultFooter');

//$footerImage = new WordFragment($footer);
$footer->addImage($imageOptions);

$pageNumber = new WordFragment($footer);
$pageNumber->addPageNumber('numerical');

$divider = new WordFragment($footer);
$divider->addText(' | ');

$docTitle = new WordFragment($footer);
$docTitle->addSimpleField('title');

$text = array();
//$text[] = $footerImage;
$text[] = $pageNumber;
$text[] = $divider;
$text[] = $docTitle;

$footer->addText($text);

$toc->addFooter(array('default' => $footer));

$toc->addText('Lorem ipsum dolor sit amet, consectetur adipisicing elit, ' .
    'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut ' .
    'enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut' .
    'aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit ' .
    'in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ' .
    'Excepteur sint occaecat cupidatat non proident, sunt in culpa qui ' .
    'officia deserunt mollit anim id est laborum.',
    array(
        'font' => 'Arial'
    ));

$_toc = $toc->createDocx();

CreateDocx::$returnDocxStructure = false;

$merge = new MultiMerge();
$merge->mergeDocx($_cover, array($_letter, $_toc), 'poc.docx', array('mergeType' => 0));

return new Response(
    '<html><body><a href="poc.docx">Download</a></body></html>'
);

Second snippet:

$footer = new WordFragment($toc, 'defaultFooter');

$footerImage = new WordFragment($footer);
$footerImage->addImage($imageOptions);

$pageNumber = new WordFragment($footer);
$pageNumber->addPageNumber('numerical');

$divider = new WordFragment($footer);
$divider->addText(' | ');

$docTitle = new WordFragment($footer);
$docTitle->addSimpleField('title');

$text = array();
$text[] = $footerImage;
$text[] = $pageNumber;
$text[] = $divider;
$text[] = $docTitle;