Forum


Replies: 13   Views: 3485
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 admin  · 26-05-2019 - 12:58

Hello,

The value of data-content needs to be a WordFragment object serialized and encoded using base64, not a string encoded using base64. This is the most simple example:

$sectionFragment = new Phpdocx\Elements\WordFragment($docx);
$sectionFragment->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>');

$html = '<phpdocx_wordfragment data-content="'.base64_encode(serialize($sectionFragment)).'" />';

So your twig filter must generate a serialized WordFragment object. You could also generate WordFragments in Drupal and use them in twig.

As it's a serialized object,  it can't be generated using phpdocx_wordfragment directly, it needs to be created previously.

Regards.