Forum


Replies: 1   Views: 201
Align textbox with outer text
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 aventyret  · 28-06-2024 - 14:33

When adding textboxes to my document the positioning gets all messed up.
But if I do this:

$docx->addText('my label);
$docx->addTextBox('myval);

The my label appears either above, under or after the textbox. I want it above. I have experimented with 

'relativeToHorizontal'
'relativeToVertical'

and

'position'


If I set a textbox to be displayed in line with text like this-> https://pasteboard.co/p733q4sfbTJ8.png it works perfect. Sorry, I only have Word in Swedish.

How do I make this setting when creating the text box in phpdocx?


 

Posted by admin  · 28-06-2024 - 21:43

Hello,

Textboxes are added using absolute positions as default. To add a textbox as "in line with text" you can set an empty value in the align option. Please note that you can also add a textbox in a WordFragment to apply extra styles (such as paragraph styles).

For example:

$docx = new CreateDocx();

$docx->addTextBox('myval', array('align' => ''));
$docx->addText('my label');
$docx->addBreak();

$textBoxFragment = new WordFragment($docx);
$textBoxFragment->addTextBox('myval', array('align' => ''));
$docx->addText([$textBoxFragment], array('textAlign' => 'center'));
$docx->addText('my label');

$docx->createDocx('output');

Regards.