Documentation

Remove content

The goal of this section is to offer you some illustrative examples on how to remove specific content from a template.

The options are manifold. By providing a "needle" (the text to be searched for), you may remove from a template the following blocks of content:

  • text: (default)the text given in the needle is removed from the document,
  • bookmark: the contents bookmarked with that needle within the template,
  • paragraph: the paragraphs that contain the needle text are removed,
  • list: the lists (with all its items) that contain the needle text are removed,
  • list-item: the list items that contain the needle text are removed,
  • table: the table that contains the needle text is removed unless the text fall within a subtable,
  • table-row: the same that for table but just for a table row,
  • image: the images which alt text (title or description) include the needle text are removed,
  • chart: the charts which alt text (title or description) include the needle text are removed,
  • textbox: all textbox content of a textbox that contains the needle text is removed,
  • heading: all the contents that fall under a given heading (including subheadings) are removed whenever the heading contains the needle text.

By also providing a match we can further filter the elements to be removed. If a match is provided the needle may be removed in certain cases.

It is also important to recall that the "removal of content" is the first set of instructions to be carried out by Docxpresso when processing the JSON data.

We strongly recommend to use Docxpresso variables as needles. This is so because Word and Libreffice may introduce XML tags that are not visible but may hinder getting the expected result in the search process. Docxpresso variables are parsed to eliminate that issue and you may later delete them or set them to an empty string.

Removing text from a template

Let us first start with an example on how to remove plain text from a template.

The following JSON will remove all appeareances of the text "Text to be removed." from the provided template:

{   
    "template": "insert here the given template base64 encoded",
    "output": "odt",
    "remove": [
        {
            "options": {
                "needle": "Text to be removed.",
                "element": "text"
            }
        }
    ]
}

DOWNLOAD: Template JSON Doc

You may check that the text has been removed from the template twice. In the event that you would like only the second ocurrence to be deleted you should modify the JSON as follows:

{   
    "template": "insert here the given template base64 encoded",
    "output": "odt",
    "remove": [
        {
            "options": {
                "needle": "deleteme",
                "element": "text",
                "match": 2
            }
        }
    ]
}

DOWNLOAD: Template JSON Doc

Removing bookmarked content

The following JSON will remove all content bookmarked under the tag "deleteme":

{   
    "template": "insert here the given template base64 encoded",
    "output": "odt",
    "remove": [
        {
            "options": {
                "needle": "deleteme",
                "element": "bookmark"
            }
        }
    ]
}

DOWNLOAD: Template JSON Doc

Removing paragraphs from a template

The following JSON will remove all paragraphs (but not headings) that include the word "removed" (including the one in the table header):

{   
    "template": "insert here the given template base64 encoded",
    "output": "odt",
    "remove": [
        {
            "options": {
                "needle": "removed",
                "element": "paragraph"
            }
        }
    ]
}

DOWNLOAD: Template JSON Doc

As before we could have choosen a single ocurrence with the help of the match parameter. We leave that as an exercise to the reader.

Removing lists and list-items from a template

The following JSON will remove the list item that includes the text "Item 1":

{   
    "template": "insert here the given template base64 encoded",
    "output": "odt",
    "remove": [
        {
            "options": {
                "needle": "Item 1",
                "element": "list-item"
            }
        }
    ]
}

DOWNLOAD: Template JSON Doc

If we want to remove the whole list we only need to change the option element to list:

{   
    "template": "insert here the given template base64 encoded",
    "output": "odt",
    "remove": [
        {
            "options": {
                "needle": "Item 1",
                "element": "list"
            }
        }
    ]
}

DOWNLOAD: Template JSON Doc

Removing tables and table-rows from a template

If we want to remove a particular table row including the text "First" we need to use the following JSON:

{   
    "template": "insert here the given template base64 encoded",
    "output": "odt",
    "remove": [
        {
            "options": {
                "needle": "First",
                "element": "table-row"
            }
        }
    ]
}

DOWNLOAD: Template JSON Doc

In case we want to remove the whole table we have just to modify the element property:

{   
    "template": "insert here the given template base64 encoded",
    "output": "odt",
    "remove": [
        {
            "options": {
                "needle": "First",
                "element": "table"
            }
        }
    ]
}

DOWNLOAD: Template JSON Doc

Removing images from a template

In case we want to remove an image with an alt text ({{my_image}} in this particular case):

{   
    "template": "insert here the given template base64 encoded",
    "output": "odt",
    "remove": [
        {
            "options": {
                "needle": "my_image",
                "element": "image"
            }
        }
    ]
}

DOWNLOAD: Template JSON Doc

We could also have chosen to remove the image because of its order of appearance to get the same result:

{   
    "template": "insert here the given template base64 encoded",
    "output": "odt",
    "remove": [
        {
            "options": {
                "element": "image",
                "match": 1
            }
        }
    ]
}

DOWNLOAD: Template JSON Doc

Removing charts from a template

In case we want to remove a chart with an alt text ({{my_chart}} in this particular case):

{   
    "template": "insert here the given template base64 encoded",
    "output": "odt",
    "remove": [
        {
            "options": {
                "needle": "my_chart",
                "element": "chart"
            }
        }
    ]
}

DOWNLOAD: Template JSON Doc

We could also have chosen to remove the chart because of its order of appearance to get the same result:

{   
    "template": "insert here the given template base64 encoded",
    "output": "odt",
    "remove": [
        {
            "options": {
                "element": "chart",
                "match": 1
            }
        }
    ]
}

DOWNLOAD: Template JSON Doc

Removing textboxes from a template

In case we want to remove a textbox including the text "required":

{   
    "template": "insert here the given template base64 encoded",
    "output": "odt",
    "remove": [
        {
            "options": {
                "needle": "required",
                "element": "textbox"
            }
        }
    ]
}

DOWNLOAD: Template JSON Doc

Removing content under a heading

We will remove a heading of level 2 that contains the text "removed":

{   
    "template": "insert here the given template base64 encoded",
    "output": "odt",
    "remove": [
        {
            "options": {
                "needle": "removed",
                "element": "heading",
                "heading-level": 2
            }
        }
    ]
}

DOWNLOAD: Template JSON Doc

Removing multiple elements

We can, of course, combine any of the previous:

{   
    "template": "insert here the given template base64 encoded",
    "output": "odt",
    "remove": [
        {
            "options": {
                "needle": "removed",
                "element": "heading",
                "heading-level": 2
            }
        },
        {
            "options": {
                "element": "chart",
                "match": 1
            }
        },
        {
            "options": {
                "needle": "Item 1",
                "element": "list-item"
            }
        }
    ]
}

DOWNLOAD: Template JSON Doc