How to determine which layer an element belongs to?

Question:

I want to determine which layer an element belongs to, how can I do that?

Answer:

The following code will run through all the page contents, and using a Stack, pushes and pops the current OC layer. Elements are apart of the OC layer that is on the top of the stack.

Note, not all Marked Content is part of a layer, so the if the top most item in the stack has IsLayer false, then ignore that. You want the top IsLayer == true item to know the OC. This is because OC and non-OC marked content share the same EMC (end marked content) operator in the stream, so only by using a single stack can you track what to pop off.

ElementReaderTest.cs (4.3 KB)