Forum


Replies: 13   Views: 3489
Add section and change page orientation with htmlextended
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 gmakstutis  · 26-05-2019 - 18:19

OK. Trying to generate the tags, with encoding in a Drupal theme preprocess function. In this, we pass the final tag value as a Twig theme variable.

use Drupal\views\Views;
use Drupal\Core\Url;
use Drupal\node\Entity\Node;

/**
 * @param $variables
 */
function starkprint_preprocess_node(&$variables){

    $landscape_fragment = new Phpdocx\Elements\WordFragment($docx);
    $landscape_fragment->addWordML('<w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:pPr><w:sectPr><w:type w:val="nextPage"/><w:pgSz w:code="9" w:h="11906" w:orient="landscape" w:w="16838"/><w:pgMar w:bottom="850" w:footer="708" w:gutter="0" w:header="708" w:left="1077" w:right="1077" w:top="850"/><w:cols w:num="1" w:space="708"/><w:docGrid w:linePitch="360"/></w:sectPr></w:pPr></w:p>');
        
     $landscape = '<phpdocx_wordfragment data-content="'.base64_encode(serialize($landscape_fragment)).'" />';
     $variables['landscape'] = $landscape;

     $portrait_fragment = new Phpdocx\Elements\WordFragment($docx);
     $portrait_fragment->addWordML('<w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:pPr><w:sectPr><w:pgSz w:code="9" w:h="16838" w:orient="portrait" w:w="11906"/><w:pgMar w:bottom="850" w:footer="708" w:gutter="0" w:header="708" w:left="1077" w:right="1077" w:top="850"/><w:cols w:num="1" w:space="708"/><w:docGrid w:linePitch="360"/></w:sectPr></w:pPr></w:p>');
        
     $portrait = '<phpdocx_wordfragment data-content="'.base64_encode(serialize($portrait_fragment)).'" />';
     $variables['portrait'] = $portrait;
}

In the Twig template, we put:

{{ portrait }} {# this should give us the phpdocx tag for portrait layout #}

...Text to be portrait orientation...

{{ landscape }} {# this should give us the phpdocx tag for landscape layout #}

...Text to be landscape orientation...

But... this isn't working either. Do I need a 'use' statement, in order to call the 'new Phpdocx\...'?

Is there something else I should be trying?

Thanks