Forum


Replies: 3   Views: 193
A label next to a checkbox
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  · 11-09-2024 - 13:49

Hello,

You need to create a WordFragment and add it as inline content. addStructuredDocumentaTag supports working as an inline WordFragment since the release of phpdocx 13.5.

In the Contents/addStructuredDocumentaTag/sample_1.php example included in the package you can find the following code that illustrates how to add a checkbox and text in the same paragraph:

// checkbox added as WordFragment
$checkboxFragment = new WordFragment($docx, 'document');
$checkboxFragment->addStructuredDocumentTag('checkbox', ['fontSize' => 11, 'checked' => true]);
$docx->addText([array('text' => 'Checkbox: ', 'fontSize' => 12), $checkboxFragment]);

To add the checkbox and then the text you need to set them in the required order:

// checkbox added as WordFragment
$checkboxFragment = new WordFragment($docx, 'document');
$checkboxFragment->addStructuredDocumentTag('checkbox', ['fontSize' => 11, 'checked' => true]);
$docx->addText([$checkboxFragment, array('text' => ' checkbox', 'fontSize' => 12)]);

Regards.