Forum


Replies: 3   Views: 149
A label next to a checkbox

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.