Forum


Replies: 3   Views: 2547
Highlight block of text in docx template
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 arnaudbouchard  · 31-10-2017 - 06:39

Hi there,

We are working with docx templates and looking for a way to highlight a particular block of text instead of removing it.

For example, we might have a docx template with a paragraph enclosed in block placeholders:

$BLOCK_varName$

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

$BLOCK_varName$

But instead of using:

$docx->deleteTemplateBlock('varName')

We want to highlight this text in a different color.

How would you do this?

 

Thanks in advance,

Arnaud

Posted by admin  · 31-10-2017 - 07:01

Hello,

What version and license of phpdocx are you using? You can higlight keywords using the searchAndHighlight method, or use DOCXPath to highlight a whole paragraph (or multiple contents). Both features are available in Advanced and Premium licenses.

Regards.

Posted by arnaudbouchard  · 01-11-2017 - 01:05

I am using the 7.5 version, Advanced license.

From what I understand the searchAndHighlight function only works for a know string of text. In my case, I want to highligh a block of text contained between two $BLOCK_xxx$ placeholders. There could be multiple block of texts enclosed with these placeholders as well in the template, and my script doesn't know in advance what the text inside will be.

Posted by admin  · 01-11-2017 - 09:30

Hello,

You can use DOCXPath to insert a highlight tag to all w:rPr tags surrounded by the block placeholders.

To accomplish this you need to use a customQuery with the insertWordFragment method.

DOCXCustomizer, available only in Premium licenses, is the easiest way to accomplish what you need, as it allows to change DOCX styles on-the-fly.

As your username doesn't have any license tied, please send to contact[at]phpdocx.com the username or email of the user that has purchased the license.

Regards.