Forum


Replies: 1   Views: 1873
Working example on html_extended footer?
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  · 18-12-2019 - 08:48

Hi guys,

I am trying to sort out my Footer, but I cannot seem to find in the documentation what I need.

First question:

$html = '
    <phpdocx_footer>
        <phpdocx_pagenumber data-target="defaultFooter" data-type="numerical" data-fontSize="10" /><phpdocx_text data-target="defaultFooter" data-text=" | " data-fontSize="10" /><phpdocx_simplefield data-target="defaultFooter" data-fieldName="title" data-fontSize="10" />
    </phpdocx_footer>
';
$docx->embedHTML($html, array('useHTMLExtended' => true));

$docx->createDocx('html.docx');

From a content-perspective, this seems to work. However, it renders as:

1
|
TITLE

whereas I would like to display it as:

1  |  TITLE

Any suggestions? I basically need something similar as the snippet below (which does work):

        $imageOptions = array(
            'src' => $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($toc, 'defaultFooter');
        $footerImage->addImage($imageOptions);

        $pageNumber = new WordFragment($toc, 'defaultFooter');
        $pageNumber->addPageNumber('numerical');

        $divider = new WordFragment($toc, 'defaultFooter');
        $divider->addText('  |  ');

        $docTitle = new WordFragment($toc, 'defaultFooter');
        $docTitle->addSimpleField('title');

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

        $footer->addText($text);

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

Second, related question:

if I try to add an image in the footer, it seems not to work. I have obtained the sample snippet in /Core/EmbedHTML/sample_6.php. There, the reference is included: 

<phpdocx_image data-src="../../img/image.png" data-imageAlign="center" data-scaling="50" />

In a regular inclusion, this works. However, if I copy this exact same code into my HTML Extended snippet, so that it reads the following, it does not work.

$html = '
    <phpdocx_footer>
        <phpdocx_pagenumber data-target="defaultFooter" data-type="numerical" data-fontSize="10" /><phpdocx_text data-target="defaultFooter" data-text=" | " data-fontSize="10" /><phpdocx_simplefield data-target="defaultFooter" data-fieldName="title" data-fontSize="10" />
<phpdocx_image data-src="../../img/image.png" data-imageAlign="center" data-scaling="50" />
    </phpdocx_footer>
';
$docx->embedHTML($html, array('useHTMLExtended' => true));

$docx->createDocx('html.docx');

Basically, I am aiming to translate the working snippet above to a HTML Extended version.
Thank you for your help and suggestions!