Beispiel #1
0
 /// <summary>Create instance of document outline.</summary>
 /// <param name="title">the text that shall be displayed on the screen for this item.</param>
 /// <param name="content">Outline dictionary</param>
 /// <param name="parent">
 /// parent outline.
 /// <see cref="AddOutline(System.String, int)"/>
 /// and
 /// <see cref="AddOutline(System.String)"/>
 /// instead.
 /// </param>
 internal PdfOutline(String title, PdfDictionary content, iText.Kernel.Pdf.PdfOutline parent)
 {
     this.title   = title;
     this.content = content;
     this.parent  = parent;
     this.pdfDoc  = parent.pdfDoc;
     content.MakeIndirect(parent.pdfDoc);
 }
Beispiel #2
0
        /// <summary>
        /// Adds an
        /// <c>PdfOutline</c>
        /// as a child to existing
        /// <c>PdfOutline</c>
        /// and put it to the end of the existing
        /// <c>PdfOutline</c>
        /// children list.
        /// </summary>
        /// <param name="outline">an outline to add.</param>
        /// <returns>just created outline</returns>
        public virtual iText.Kernel.Pdf.PdfOutline AddOutline(iText.Kernel.Pdf.PdfOutline outline)
        {
            iText.Kernel.Pdf.PdfOutline newOutline = AddOutline(outline.GetTitle());
            newOutline.AddDestination(outline.GetDestination());
            IList <iText.Kernel.Pdf.PdfOutline> children = outline.GetAllChildren();

            foreach (iText.Kernel.Pdf.PdfOutline child in children)
            {
                newOutline.AddOutline(child);
            }
            return(newOutline);
        }
Beispiel #3
0
        /// <summary>
        /// Adds an
        /// <c>PdfOutline</c>
        /// as a child to existing <CODE>PdfOutline</CODE>
        /// and put it to specified position in the existing <CODE>PdfOutline</CODE> children list
        /// </summary>
        /// <param name="title">an outline title</param>
        /// <param name="position">
        /// a position in the current outline child List where a new outline should be added.
        /// If the position equals -1, then the outline will be put in the end of children list.
        /// </param>
        /// <returns>created outline</returns>
        /// <exception cref="iText.Kernel.PdfException"/>
        public virtual iText.Kernel.Pdf.PdfOutline AddOutline(String title, int position)
        {
            if (position == -1)
            {
                position = children.Count;
            }
            PdfDictionary dictionary = new PdfDictionary();

            iText.Kernel.Pdf.PdfOutline outline = new iText.Kernel.Pdf.PdfOutline(title, dictionary, this);
            dictionary.Put(PdfName.Title, new PdfString(title, PdfEncodings.UNICODE_BIG));
            dictionary.Put(PdfName.Parent, content);
            if (children.Count > 0)
            {
                if (position != 0)
                {
                    PdfDictionary prevContent = children[position - 1].GetContent();
                    dictionary.Put(PdfName.Prev, prevContent);
                    prevContent.Put(PdfName.Next, dictionary);
                }
                if (position != children.Count)
                {
                    PdfDictionary nextContent = children[position].GetContent();
                    dictionary.Put(PdfName.Next, nextContent);
                    nextContent.Put(PdfName.Prev, dictionary);
                }
            }
            if (position == 0)
            {
                content.Put(PdfName.First, dictionary);
            }
            if (position == children.Count)
            {
                content.Put(PdfName.Last, dictionary);
            }
            if (children.Count > 0)
            {
                int count = (int)this.content.GetAsInt(PdfName.Count);
                if (count > 0)
                {
                    content.Put(PdfName.Count, new PdfNumber(count++));
                }
                else
                {
                    content.Put(PdfName.Count, new PdfNumber(count--));
                }
            }
            else
            {
                this.content.Put(PdfName.Count, new PdfNumber(-1));
            }
            children.Add(position, outline);
            return(outline);
        }
Beispiel #4
0
        /// <summary>remove this outline from the document.</summary>
        /// <exception cref="iText.Kernel.PdfException"/>
        internal virtual void RemoveOutline()
        {
            PdfName type = content.GetAsName(PdfName.Type);

            if (type != null && type.Equals(PdfName.Outlines))
            {
                pdfDoc.GetCatalog().Remove(PdfName.Outlines);
                return;
            }
            iText.Kernel.Pdf.PdfOutline         parent   = this.parent;
            IList <iText.Kernel.Pdf.PdfOutline> children = parent.children;

            children.Remove(this);
            PdfDictionary parentContent = parent.content;

            if (children.Count > 0)
            {
                parentContent.Put(PdfName.First, children[0].content);
                parentContent.Put(PdfName.Last, children[children.Count - 1].content);
            }
            else
            {
                parent.RemoveOutline();
                return;
            }
            PdfDictionary next = content.GetAsDictionary(PdfName.Next);
            PdfDictionary prev = content.GetAsDictionary(PdfName.Prev);

            if (prev != null)
            {
                if (next != null)
                {
                    prev.Put(PdfName.Next, next);
                    next.Put(PdfName.Prev, prev);
                }
                else
                {
                    prev.Remove(PdfName.Next);
                }
            }
            else
            {
                if (next != null)
                {
                    next.Remove(PdfName.Prev);
                }
            }
        }