Ejemplo n.º 1
0
        // extension method to the outlines
        // in the itext package
        public static int GetPageNumber(this PdfOutline outline, PdfDocument doc)
        {
            try
            {
                PdfDictionary dict = outline.GetContent().GetAsDictionary(PdfName.A);

                if (dict == null)
                {
                    PdfArray array = outline.GetContent().GetAsArray(PdfName.Dest);

                    if (array != null)
                    {
                        PdfObject obj = array.SubList(0, 1)[0];

                        if (obj is PdfNumber)
                        {
                            return(((PdfNumber)obj).IntValue() + 1);
                        }
                        else if (obj is PdfDictionary)
                        {
                            return(doc.GetPageNumber((PdfDictionary)obj));
                        }
                        else
                        {
                            return(-3);
                        }
                    }
                    else
                    {
                        return(-1);
                    }
                }

                dict = dict.GetAsArray(PdfName.D).GetAsDictionary(0);

                return(doc.GetPageNumber(dict));
            }
#pragma warning disable CS0168 // The variable 'e' is declared but never used
            catch (Exception e)
#pragma warning restore CS0168 // The variable 'e' is declared but never used
            {
                return(-2);
            }
        }
Ejemplo n.º 2
0
        /// <summary>the next element in the entire hierarchy</summary>
        /// <param name="outline"></param>
        /// <exception cref="iText.Kernel.PdfException"/>
        private PdfOutline GetAbsoluteTreeNextOutline(PdfOutline outline)
        {
            PdfObject  nextPdfObject  = outline.GetContent().Get(PdfName.Next);
            PdfOutline nextPdfOutline = null;

            if (outline.GetParent() != null && nextPdfObject != null)
            {
                foreach (PdfOutline pdfOutline in outline.GetParent().GetAllChildren())
                {
                    if (pdfOutline.GetContent().GetIndirectReference().Equals(nextPdfObject.GetIndirectReference()))
                    {
                        nextPdfOutline = pdfOutline;
                        break;
                    }
                }
            }
            if (nextPdfOutline == null && outline.GetParent() != null)
            {
                nextPdfOutline = GetAbsoluteTreeNextOutline(outline.GetParent());
            }
            return(nextPdfOutline);
        }