Forum


Replies: 1   Views: 4138
How can i set position to watermark to 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 gh_ost  · 23-10-2017 - 06:49

Hellow! 

I want add water makr to footer for even page.

My frist variant is


        $footerImage = new WordFragment($word,' defaultFooter');
        $footerImage->addImage([
            'src' => 'img/logo_blue_sidebar_en.png',
            'height' => 50,
            'width' => 150,
        ]);
        
        $word->addFooter(['even' => $footerImage]);
        $word->createDocx($documentName);

  But after replace some elements to HTML this image in footer disappeared. If i set image to footer after replacing variables to HTML elements i can't add image to footer. 

$htmlFontSize = '18.5px';
        $docx = new CreateDocxFromTemplate($documentName.'.docx');
        //ЗаменÑм Ð¿Ð¾Ð»Ñ Ð³Ð´Ðµ наш переменные на текÑÑ‚ где иÑпользовалоÑÑŒ CKEDITOR
        $docx->replaceVariableByHTML('MEMBERSHIP', 'block', '<div style="font-size: '.$htmlFontSize.'; ">'.$membership.'</div>', ['isFile' => false, 'parseDivsAsPs' => true, 'downloadImages' => false]);

        if($person->expertise_experience_has == 1)
            $docx->replaceVariableByHTML('EXPERIENCE', 'block', '<div style="font-size: '.$htmlFontSize.'; ">'.$expertiseExperience.'</div>', ['isFile' => false, 'parseDivsAsPs' => true, 'downloadImages' => false]);

        $docx->replaceVariableByHTML('PUBLICATIONS', 'block', '<div style="font-size: '.$htmlFontSize.'; ">'.$publications.'</div>', ['isFile' => false, 'parseDivsAsPs' => true, 'downloadImages' => false]);
        $docx->replaceVariableByHTML('PATENTS', 'block', '<div style="font-size: '.$htmlFontSize.'; ">'.$receivedPatents.'</div>', ['isFile' => false, 'parseDivsAsPs' => true, 'downloadImages' => false]);
        //Download
        $docx->createDocxAndDownload($documentName);
        unlink($documentName.'.docx');

 On second variant i use: 

//WaterMark
        $waterMarkParams = [
            'image' => 'img/logo_blue_sidebar_en.png',
            'height' => 50,
            'width' => 150,
            'decolorate' => false,
        ];

        $docx = new DocxUtilities();
        $source = $documentName.'.docx';
        $target = $documentName.'.docx';
        $docx->watermarkDocx($source, $target, $type = 'image', $options = $waterMarkParams);
        //end Watermark

I can't set position to lower left corner. How can i solve this problem? Thanks 

Posted by admin  · 23-10-2017 - 11:24

Hello,

Watermarks are always added centered to the page. You can scale the image added as watermark and add watermarks per section.

If you need to add an image to even pages, the easiest approach is to create a custom DOCX template with headers and footers with an image placeholder, then import it to your DOCX and then replace the placeholder image:

https://www.phpdocx.com/api-documentation/layout-and-general/import-headers-and-footers-Word-document-with-PHP

https://www.phpdocx.com/api-documentation/templates/replace-placeholder-image-Word-document

Anyway, adding WordFragments with images to headers and footers work perfectly and they aren't overwrite unless you remove them.

Just to comment other approach, since phpdocx 7.5, the addImage method includes the relativeToHorizontal and relativeToVertical options to add images relative to margins, pages...:

https://www.phpdocx.com/api-documentation/word-content/insert-image-Word-document-with-PHP

Regards.