In case you are creating PDF layers as illustrated in PDFLayers sample
project (
http://www.pdftron.com/net/samplecode.html#PDFLayers) you can
use the following approach to identify the layer to which the content
belongs.
- When you encounter Form XObject, you can obtain for dictionary using
element.GetXObject().
- If the dictionary contains OC entry, the form content is part of
some optional content group/layer.
- For simple groups you can obtain the layer name using
group.GetName().
// C# pseudocode (JAVA or C++ cose is essentially the same)
string cur_layer_name;
void ProcessElements(ElementReader reader) {
Element element;
while ((element = reader.Next()) != null) {
switch (element.GetType()) {
case Element.Type.e_path:
break;
case Element.Type.e_text:
break;
case Element.Type.e_form: {
Obj xobject = element.GetXObject();
Obj oc = xobject.FindObj("OC");
if (oc != null) {
// Check if this is OC Membership dictionary or OCG
pdftron.PDF.OCG.OCMD md = new pdftron.PDF.OCG.OCMD(oc);
if (md.IsValid()) {
// cur_layer_name = traverse the array of OCGs using
md.GetOCGs();
}
else {
pdftron.PDF.OCG.Group grp = new pdftron.PDF.OCG.Group(oc);
if (grp.IsValid()) {
cur_layer_name = grp.GetName();
}
}
}
reader.FormBegin();
ProcessElements(reader);
reader.End();
break;
}
}
}
}