Q: Does PDFNet support for PDF layers?
Also when reading through the geometry in a PDF document... using an
ElementReader. Is there a way to find out what layer this geom is
on.... or alternatively while looping through the layers... is there a
way to get access to the geom on it ?
---------
A: PDFNet SDK supports PDF layers (OCG). Using ElementReader you can
determine to what layer the element is associated with. This is
illustrated in the following C# pseudocode:
- 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, VB, or C++ 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;
}
}
}
For examples of how to tell PDFNet rasterizer to turn 'on' and 'off'
specific layers during content rendering please take a look at the
following projects:
http://www.pdftron.com/net/samplecode.html#PDFLayers
http://www.pdftron.com/net/samplecode.html#PDFView
For an example of how to programmatically create PDF documents with
layers, please see PDFLayers (http://www.pdftron.com/net/
samplecode.html#PDFLayers).
You may also want to refer to 'pdftron.PDF.OCG' namespace in PDFNet
SDK API Reference (http://www.pdftron.com/net/html/
namespacepdftron_1_1PDF_1_1OCG.html or http://www.pdftron.com/net/Javadoc
for Java developers) for more details on specific methods and classes
related to PDF layers and Optional Content Groups (OCGs).