/// <summary>Fills the underlying PdfDictionary object with the current layers and their settings.</summary> /// <remarks> /// Fills the underlying PdfDictionary object with the current layers and their settings. /// Note that it completely regenerates the dictionary, so your direct changes to the dictionary /// will not take any affect. /// </remarks> /// <param name="removeNonDocumentOcgs"> /// the flag indicating whether it is necessary /// to delete OCGs not from the current document /// </param> /// <returns>the resultant dictionary</returns> public virtual PdfObject FillDictionary(bool removeNonDocumentOcgs) { PdfArray gr = new PdfArray(); foreach (PdfLayer layer in layers) { if (layer.GetTitle() == null) { gr.Add(layer.GetIndirectReference()); } } GetPdfObject().Put(PdfName.OCGs, gr); // Save radio groups. PdfArray rbGroups = null; PdfDictionary d = GetPdfObject().GetAsDictionary(PdfName.D); if (d != null) { rbGroups = d.GetAsArray(PdfName.RBGroups); } d = new PdfDictionary(); if (rbGroups != null) { d.Put(PdfName.RBGroups, rbGroups); } d.Put(PdfName.Name, new PdfString(CreateUniqueName(), PdfEncodings.UNICODE_BIG)); GetPdfObject().Put(PdfName.D, d); IList <PdfLayer> docOrder = new List <PdfLayer>(layers); for (int i = 0; i < docOrder.Count; i++) { PdfLayer layer = docOrder[i]; if (layer.GetParent() != null) { docOrder.Remove(layer); i--; } } PdfArray order = new PdfArray(); foreach (Object element in docOrder) { PdfLayer layer = (PdfLayer)element; GetOCGOrder(order, layer); } d.Put(PdfName.Order, order); PdfArray off = new PdfArray(); foreach (Object element in layers) { PdfLayer layer = (PdfLayer)element; if (layer.GetTitle() == null && !layer.IsOn()) { off.Add(layer.GetIndirectReference()); } } if (off.Size() > 0) { d.Put(PdfName.OFF, off); } else { d.Remove(PdfName.OFF); } PdfArray locked = new PdfArray(); foreach (PdfLayer layer in layers) { if (layer.GetTitle() == null && layer.IsLocked()) { locked.Add(layer.GetIndirectReference()); } } if (locked.Size() > 0) { d.Put(PdfName.Locked, locked); } else { d.Remove(PdfName.Locked); } d.Remove(PdfName.AS); AddASEvent(PdfName.View, PdfName.Zoom); AddASEvent(PdfName.View, PdfName.View); AddASEvent(PdfName.Print, PdfName.Print); AddASEvent(PdfName.Export, PdfName.Export); if (removeNonDocumentOcgs) { this.RemoveNotRegisteredOcgs(); } return(GetPdfObject()); }