pdx:searchAndHighlight

Searches for keywords within a Word document and highlights them.

Description

Element definition

x
 
1
<pdx:utilities>
2
    <pdx:searchAndHighlight pdx:src="" pdx:target="" pdx:searchTerm="" pdx:highlightColor="">
3
        <pdx:valueContext pdx:value="" />
4
        <pdx:valueContext pdx:value="" />
5
    </pdx:searchAndHighlight>
6
</pdx:utilities>
7

This element allows the highlighting of plain text in a DOCX document.

Attributes and sub-elements

src

The path to the source Word document.

target

The path to the Word document resulting after the text highlighting.

searchTerm

The string of text that we want to highlight.

options

The possible keys and values are:

key Description
highlightColor

the color used for the highlighting:

  • black
  • blue
  • cyan
  • green
  • magenta
  • red
  • yellow
  • white
  • darkBlue
  • darkCyan
  • darkGreen
  • darkMagenta
  • darkRed
  • darkYellow
  • darkGray
  • lightGray
  • none

The default value is ‘yellow’.

document If true highlights the search string in the body of the document. The default value is true.
endnotes If true highlights the search string in the document endnotes. The default value is false.
comments If true highlights the search string in the document comments. The default value is false.
headersAndFooters If true highlights the search string in headers and footers. The default value is true.
footnotes If true highlights the search string in the document footnotes. The default value is false.
Code samples
#Example 1

config.xml

7
 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<pdx:document xmlns:pdx="http://www.phpdocx.com/main">
3
    <pdx:config>
4
        <pdx:output pdx:name="output" pdx:type="docx" />
5
    </pdx:config>
6
</pdx:document>
7

content.xml

13
 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<pdx:document xmlns:pdx="http://www.phpdocx.com/main">
3
    <pdx:utilities>
4
        <pdx:searchAndHighlight pdx:source="/var/www/xmldocx/samples/files/second.docx" pdx:target="/var/www/xmldocx/samples/DocxUtilities/searchAndHighlight/output_searchAndHighlight.docx" pdx:searchTerm="data" pdx:highlightColor="green">
5
            <pdx:valueContext pdx:value="document" />
6
            <pdx:valueContext pdx:value="endnotes" />
7
            <pdx:valueContext pdx:value="comments" />
8
            <pdx:valueContext pdx:value="headersAndFooters" />
9
            <pdx:valueContext pdx:value="footnotes" />
10
        </pdx:searchAndHighlight>
11
    </pdx:utilities>
12
</pdx:document>
13

settings.xml

6
 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<pdx:document xmlns:pdx="http://www.phpdocx.com/main">
3
    <pdx:settings>
4
    </pdx:settings>
5
</pdx:document>
6
10
 
1
import os as os
2
import sys as sys
3
sys.path.append(os.path.abspath("wrappers/python/XmlDocx"))
4
import XmlDocx as XmlDocx
5
document = XmlDocx.XmlDocx("config.xml")
6
document.setDocumentProperties("settings.xml")
7
document.addContent("content.xml")
8
document.setXmlDocxPath("xmldocx path")
9
document.render()
10

The resulting Word document looks like: