Forum


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

Posted by admin  · 11-09-2024 - 15:59

Hello,

When a content is added as inline content, only inline styles remain. Block contents/styles are removed.

You can add a rich text content as inline content:

// richText
$richTextFragment = new WordFragment($docx, 'document');
$options = array(
        'placeholderText' => 'A content in a rich text',
        'alias' => 'Rich text',
);
$richTextFragment->addStructuredDocumentTag('richText', $options);
$docx->addText([array('text' => 'Rich text: ', 'fontSize' => 12), $richTextFragment]);

(block styles are removed from the inline contents).

You can also apply paragraph options to the whole paragraph that contains inline contents:

$paragraphOptions = array(
        'textAlign' => 'center',
);
$docx->addText([array('text' => 'Rich text: ', 'fontSize' => 12), $richTextFragment], $paragraphOptions);

but these styles apply to the entire paragraph.

The addText method supports adding character borders to run-of-text contents:

$docx->addText([array('text' => 'Rich text: ', 'fontSize' => 12, 'characterBorder' => array('single')), $richTextFragment], $paragraphOptions);

 but the characterBorder style is not supported when creating a structured document tag content in the current stable version of phpdocx.

The current testing branch includes more rPr styles that can be applied to structured document tags. For example to include a character border:

$richTextFragment = new WordFragment($docx, 'document');
$options = array(
        'placeholderText' => 'A content in a rich text',
        'alias' => 'Rich text',
        'characterBorder' => array('type' => 'single'),
);
$richTextFragment->addStructuredDocumentTag('richText', $options);

This is a run-of-text style, so it remains when adding the inline content with addText.
Please note that changes from the testing branch are only available for licenses with active LUS (https://www.phpdocx.com/updates). If you purchase LUS for your license (MY PHPDOCX page after login), please send a message to contact[at]phpdocx.com and we'll send you the updated class.

A similar approach can be done using DOCXCustomizer in the stable release of phpdocx, but this feature is only available in Premium licenses.

Regards.