class PDF::Reader::AdvancedTextRunFilter

Filter a collection of TextRun objects based on a set of conditions. It can be used to filter text runs based on their attributes. The filter can return the text runs that matches the conditions (only) or the text runs that do not match the conditions (exclude).

You can filter the text runs based on all its attributes with the operators mentioned in VALID_OPERATORS. The filter can be nested with ‘or’ and ‘and’ conditions.

Examples:

  1. Single condition

AdvancedTextRunFilter.exclude(text_runs, text: { include: ‘sample’ })

  1. Multiple conditions (and)

AdvancedTextRunFilter.exclude(text_runs, {

font_size: { greater_than: 10, less_than: 15 }

})

  1. Multiple possible values (or)

AdvancedTextRunFilter.exclude(text_runs, {

font_size: { equal: [10, 12] }

})

  1. Complex AND/OR filter

AdvancedTextRunFilter.exclude(text_runs, {

and: [
  { font_size: { greater_than: 10 } },
  { or: [
    { text: { include: "sample" } },
    { width: { greater_than: 100 } }
  ]}
]

})