Search code examples
pdflayerocg

how to make pdf layers(optional content group) in tree structure


I have not long ago post a quesion about how to use the optional content group in pdf. But now I have a new question. How to make these optional content group in a tree structure.

For example. I have 4 different layers. these layers are all OCG layer. 3 layers is text labels, 1 layer have veccotr graphic. So i want it shown as this:

Alllayers
   ---labels
       --layer1
       --layer2
       --layer3
   ---layer4

I use a pdf doc as an example enter image description here

this is in chinese, the chinses character is the name of the layer. Just this meaning.


Solution

  • The answer to this question will depend on which pdf library you are using to generate your files. In general, you will need to produce a file that has an Order array in the optional content configuration dictionary that represents the tree that you want to display.

    From the PDF Reference Document:

    Key: Order
    Type: array
    Description: (Optional) An array specifying the order for presentation of optional content groups in a conforming reader’s user interface. The array elements may include the following objects:
    -Optional content group dictionaries, whose Name entry shall bedisplayed in the user interface by the conforming reader.
    -Arrays of optional content groups which may be displayed by a conforming reader in a tree or outline structure. Each nested array may optionally have as its first element a text string to be used as a non-selectable label in a conforming reader’s user interface.