How to get the name of an Element's OCG Layer?

Question:
How do I get the name of the layer each Element belongs to?

Answer:

Element element;
# iterate through the elements
while ((element = page_reader.next()) != null) {
        # get the element's property dictionary, returns NULL if one is not present
        obj propDict = element.GetMCPropertyDict();
        # get the name of the layer
        string layerName = propDict.FindObj("Name").GetAsPDFText();
}
1 Like

Thank you for giving the code of the Element of the OCG layer.