8. Named Strings

Named strings are CSS variables that can store textual content. This textual content is copied from the actual textual content of an element. You can store the textual content of a specific element in a named string using an apropriate selector and the string-set property. This value can be accessed using the string() function.

For example, one possible use of named strings would be to first store the value of the chapter title in a named string, then add this value to the bottom page margin in order to display the name of the current chapter on the bottom of every page. Example:

@page {
    @bottom { 
        content: "Chapter: " string(chaptertitle);
    }
}
chapter > title { string-set: chaptertitle self; }

In the example above, the value of the textual content of the first title element that is a descendent of a chapter is assigned to the named string chaptertitle. We then add the chapter title to the bottom of each page using generated content by recalling the value of the chaptertitle using the string() function.

PDFreactor currently supports the use of the following keywords with the string-set() property:

self - stores the entire textual content of the selected element in the named string variable.

first-letter - stores only the first letter of the textual content of the selected element.

The string-set property currently does not support the keywords before and after as defined by CSS3.

The keywords accepted by the string-set property are:

start - the starting value of the named string on the current page is used.

first - the first value assigned to the named string on the current page is used.

last - the last value assigned to the named string on the current page page is used.

last-exept - the last value assigned to the named string on the current page is used, unless this is the first page where a value is assigned to this named string. If this is the case, an empty string is used.

Note:

The keywords start, first, last and last-exept do not have an effect outside of page margin boxes.