StyleManagerRegisterStyle Method

Apitron PDF Kit help
Apitron.PDF.Kit library for .NET
Registers style and provides access to it using its selector. Selector – is a rule that defines which elements should be styled with the given set of properties, it consists of a rule itself that looks very similar to CSS notation and a property set.

Supported selectors:

  • Universal selector (“*”), selects all elements in document, represented as *.
  • Type selector (“_typename_”), selects all elements of the given type. E.g. “textbox”. It's possible to list several types using comma, e.g. "textbox, section, image".
  • Class selector (“.classname”), selects all elements that belong to specific class. E.g. “*.myclass” selects all elements with class “myclass”. Because element can have multiple classes set, it is possible to specify several classes in selector, for example “*.myclass1.myclass2”.
  • Id selector(“#elementID”). An element can have an id set, and this selector matches the element with specific id. Sample: “texbox#help”, selects the textbox element with ID “help”
  • Child selector (“[ancestor]>child”), selects all elements that are immediate children of ancestor element, square brackets indicate optionality of the ancestor, in case of absence it will behave like as “*” would be set.


    “> textbox” – same as “textbox”, selects all textboxes that are children of any element.

    “section > textbox ” – select all textboxes which are placed in sections

    “flowdocument > section> textbox.subheader” – selects all textboxes with class ”subheader” set, nested under any section that is a child of root element.

  • Descendant selector(“element_1 element_2”), selects all elements which are descendants of the given element.


    “section#header image” – selects all images in section with ID=”header” regardless of the nesting.

  • Adjacent element selector (“predessor + element”), selects the element that precedes some element.


    “image + textbox” – selects all images that precede a textbox.

How the styles are being resolved:

  1. Directly assigned value is requested first. It's the value you set using arbitraty property of the content element.
  2. If no value is set using p.1, we are trying to find its value using selectors and styles registered. a) look for all selectors that match given element b) select value according to matching rules (these rules are: specificity of the selector and order of addition, if specificity is the same, we use order)
  3. Request parent's value if property is inheritable and use the same scheme

In general this styling system is close to CSS used with HTML, so one familiar with the latter can easily find similarities.

Namespace:  Apitron.PDF.Kit.Styles
Assembly:  Apitron.PDF.Kit (in Apitron.PDF.Kit.dll) Version: (

public void RegisterStyle(
	string selector,
	Style style


Type: SystemString
The selector.
Type: Apitron.PDF.Kit.StylesStyle
The style.

ArgumentNullException if one of the arguments is null.
SelectorParseException if selector has invalid format.
See Also