static void Main(string[] args)
        {
            Console.WriteLine("ListLayers Sample:");

            // ReSharper disable once UnusedVariable
            using (Library lib = new Library())
            {
                Console.WriteLine("Initialized the library.");

                String sInput = Library.ResourceDirectory + "Sample_Input/Layers.pdf";

                if (args.Length > 0)
                {
                    sInput = args[0];
                }

                Console.WriteLine("Input file: " + sInput);

                Document doc = new Document(sInput);

                IList <OptionalContentGroup> ocgs = doc.OptionalContentGroups;
                foreach (OptionalContentGroup ocg in ocgs)
                {
                    Console.WriteLine(ocg.Name);
                    Console.Write("  Intent: [");
                    if (ocg.Intent.Count > 0)
                    {
                        IEnumerator <String> i = ocg.Intent.GetEnumerator();
                        i.MoveNext();
                        Console.Write(i.Current);
                        while (i.MoveNext())
                        {
                            Console.Write(", ");
                            Console.Write(i.Current);
                        }
                    }

                    Console.WriteLine("]");
                }

                OptionalContentContext ctx = doc.OptionalContentContext;
                Console.Write("Optional content states: [");
                IList <bool> states = ctx.GetOCGStates(ocgs);
                if (states.Count > 0)
                {
                    IEnumerator <bool> i = states.GetEnumerator();
                    i.MoveNext();
                    Console.Write(i.Current);
                    while (i.MoveNext())
                    {
                        Console.Write(", ");
                        Console.Write(i.Current);
                    }
                }

                Console.WriteLine("]");
            }
        }
        public void CreateLayerItems(Document doc)
        {
            DestroyLayers();
            if (doc == null)
            {
                layersInDocument = new List <LayerItems>();
                return;
            }
            int controlHeight = 0;

            docLayerContext = new OptionalContentContext(doc);
            docLayers       = doc.OptionalContentGroups;
            ocgStates       = docLayerContext.GetOCGStates(docLayers);

            if (docLayers.Count > 1)
            {
                // create the master layer control, turns on/off all layers
                masterLayer = new LayerItems(this.Width);
                masterLayer.layerName.Text    = "All Layers";
                masterLayer.Location          = new System.Drawing.Point(0, controlHeight);
                masterLayer.displayLayer.Name = "Master";
                masterLayer.printLayer.Name   = "Master";

                // add the events for when the checkboxes are clicked
                masterLayer.displayLayer.Click += new EventHandler(dleController.displayLayer_Click);
                masterLayer.printLayer.Click   += new EventHandler(dleController.printLayer_Click);

                // increase the height (y coordinate) so we do not overlap controls
                controlHeight += 65;

                // add the controls we just created to the layer manager
                this.Controls.Add(masterLayer);
            }

            layersInDocument = new List <LayerItems>(docLayers.Count);

            // create the layer items for all of the other layers that exist
            for (int i = 0; i < docLayers.Count; i++)
            {
                layersInDocument.Insert(i, new LayerItems(this.Width));
                layersInDocument[i].layerName.Text = doc.OptionalContentGroups[i].Name;
                layersInDocument[i].Location       = new System.Drawing.Point(0, controlHeight);

                // add the events for when the checkboxes are clicked
                layersInDocument[i].displayLayer.Click += new EventHandler(dleController.displayLayer_Click);
                layersInDocument[i].printLayer.Click   += new EventHandler(dleController.printLayer_Click);

                controlHeight += 65;
            }

            foreach (LayerItems l in layersInDocument)
            {
                this.Controls.Add(l);
            }

            this.Invalidate();
        }