Пример #1
0
        /// <summary>
        /// Gets the order of the layers in which they will be displayed in the layer view panel,
        /// including nesting.
        /// </summary>
        private static void GetOCGOrder(PdfArray order, PdfLayer layer)
        {
            if (!layer.IsOnPanel())
            {
                return;
            }
            if (layer.GetTitle() == null)
            {
                order.Add(layer.GetPdfObject().GetIndirectReference());
            }
            IList <PdfLayer> children = layer.GetChildren();

            if (children == null)
            {
                return;
            }
            PdfArray kids = new PdfArray();

            if (layer.GetTitle() != null)
            {
                kids.Add(new PdfString(layer.GetTitle(), PdfEncodings.UNICODE_BIG));
            }
            foreach (PdfLayer child in children)
            {
                GetOCGOrder(kids, child);
            }
            if (kids.Size() > 0)
            {
                order.Add(kids);
            }
        }
Пример #2
0
        /// <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>
        /// <returns>the resultant dictionary</returns>
        public virtual PdfObject FillDictionary()
        {
            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);
            }
            GetPdfObject().Put(PdfName.D, d);
            IList <PdfLayer> docOrder = new List <PdfLayer>(layers);

            for (int i = 0; i < docOrder.Count; i++)
            {
                PdfLayer layer_1 = docOrder[i];
                if (layer_1.GetParent() != null)
                {
                    docOrder.Remove(layer_1);
                    i--;
                }
            }
            PdfArray order = new PdfArray();

            foreach (Object element in docOrder)
            {
                PdfLayer layer_1 = (PdfLayer)element;
                GetOCGOrder(order, layer_1);
            }
            d.Put(PdfName.Order, order);
            PdfArray off = new PdfArray();

            foreach (Object element_1 in layers)
            {
                PdfLayer layer_1 = (PdfLayer)element_1;
                if (layer_1.GetTitle() == null && !layer_1.IsOn())
                {
                    off.Add(layer_1.GetIndirectReference());
                }
            }
            if (off.Size() > 0)
            {
                d.Put(PdfName.OFF, off);
            }
            else
            {
                d.Remove(PdfName.OFF);
            }
            PdfArray locked = new PdfArray();

            foreach (PdfLayer layer_2 in layers)
            {
                if (layer_2.GetTitle() == null && layer_2.IsLocked())
                {
                    locked.Add(layer_2.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);
            return(GetPdfObject());
        }
Пример #3
0
        /// <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());
        }