コード例 #1
0
        internal void BuildTree()
        {
            Hashtable numTree = new Hashtable();

            foreach (int i in parentTree.Keys)
            {
                PdfArray ar = (PdfArray)parentTree[i];
                numTree[i] = writer.AddToBody(ar).IndirectReference;
            }
            PdfDictionary dicTree = PdfNumberTree.WriteTree(numTree, writer);

            if (dicTree != null)
            {
                Put(PdfName.PARENTTREE, writer.AddToBody(dicTree).IndirectReference);
            }

            NodeProcess(this, reference);
        }
コード例 #2
0
        /**
         * Retrieves the page labels from a PDF as an array of String objects.
         * @param reader a PdfReader object that has the page labels you want to retrieve
         * @return  a String array or <code>null</code> if no page labels are present
         */
        public static String[] GetPageLabels(PdfReader reader)
        {
            int n = reader.NumberOfPages;

            PdfDictionary dict   = reader.Catalog;
            PdfDictionary labels = (PdfDictionary)PdfReader.GetPdfObjectRelease(dict.Get(PdfName.PAGELABELS));

            if (labels == null)
            {
                return(null);
            }

            String[]  labelstrings = new String[n];
            Hashtable numberTree   = PdfNumberTree.ReadTree(labels);

            int    pagecount = 1;
            String prefix    = "";
            char   type      = 'D';

            for (int i = 0; i < n; i++)
            {
                if (numberTree.ContainsKey(i))
                {
                    PdfDictionary d = (PdfDictionary)PdfReader.GetPdfObjectRelease((PdfObject)numberTree[i]);
                    if (d.Contains(PdfName.ST))
                    {
                        pagecount = ((PdfNumber)d.Get(PdfName.ST)).IntValue;
                    }
                    else
                    {
                        pagecount = 1;
                    }
                    if (d.Contains(PdfName.P))
                    {
                        prefix = ((PdfString)d.Get(PdfName.P)).ToUnicodeString();
                    }
                    if (d.Contains(PdfName.S))
                    {
                        type = ((PdfName)d.Get(PdfName.S)).ToString()[1];
                    }
                }
                switch (type)
                {
                default:
                    labelstrings[i] = prefix + pagecount;
                    break;

                case 'R':
                    labelstrings[i] = prefix + RomanNumberFactory.GetUpperCaseString(pagecount);
                    break;

                case 'r':
                    labelstrings[i] = prefix + RomanNumberFactory.GetLowerCaseString(pagecount);
                    break;

                case 'A':
                    labelstrings[i] = prefix + RomanAlphabetFactory.GetUpperCaseString(pagecount);
                    break;

                case 'a':
                    labelstrings[i] = prefix + RomanAlphabetFactory.GetLowerCaseString(pagecount);
                    break;
                }
                pagecount++;
            }
            return(labelstrings);
        }
コード例 #3
0
        /**
         * Retrieves the page labels from a PDF as an array of {@link PdfPageLabelFormat} objects.
         * @param reader a PdfReader object that has the page labels you want to retrieve
         * @return  a PdfPageLabelEntry array, containing an entry for each format change
         * or <code>null</code> if no page labels are present
         */
        public static PdfPageLabelFormat[] GetPageLabelFormats(PdfReader reader)
        {
            PdfDictionary dict   = reader.Catalog;
            PdfDictionary labels = (PdfDictionary)PdfReader.GetPdfObjectRelease(dict.Get(PdfName.PAGELABELS));

            if (labels == null)
            {
                return(null);
            }
            Hashtable numberTree = PdfNumberTree.ReadTree(labels);

            int[] numbers = new int[numberTree.Count];
            numberTree.Keys.CopyTo(numbers, 0);
            Array.Sort(numbers);
            PdfPageLabelFormat[] formats = new PdfPageLabelFormat[numberTree.Count];
            String prefix;
            int    numberStyle;
            int    pagecount;

            for (int k = 0; k < numbers.Length; ++k)
            {
                int           key = numbers[k];
                PdfDictionary d   = (PdfDictionary)PdfReader.GetPdfObjectRelease((PdfObject)numberTree[key]);
                if (d.Contains(PdfName.ST))
                {
                    pagecount = ((PdfNumber)d.Get(PdfName.ST)).IntValue;
                }
                else
                {
                    pagecount = 1;
                }
                if (d.Contains(PdfName.P))
                {
                    prefix = ((PdfString)d.Get(PdfName.P)).ToUnicodeString();
                }
                else
                {
                    prefix = "";
                }
                if (d.Contains(PdfName.S))
                {
                    char type = ((PdfName)d.Get(PdfName.S)).ToString()[1];
                    switch (type)
                    {
                    case 'R': numberStyle = UPPERCASE_ROMAN_NUMERALS; break;

                    case 'r': numberStyle = LOWERCASE_ROMAN_NUMERALS; break;

                    case 'A': numberStyle = UPPERCASE_LETTERS; break;

                    case 'a': numberStyle = LOWERCASE_LETTERS; break;

                    default: numberStyle = DECIMAL_ARABIC_NUMERALS; break;
                    }
                }
                else
                {
                    numberStyle = EMPTY;
                }
                formats[k] = new PdfPageLabelFormat(key + 1, numberStyle, prefix, pagecount);
            }
            return(formats);
        }
コード例 #4
0
 /** Gets the page label dictionary to insert into the document.
  * @return the page label dictionary
  */
 internal PdfDictionary GetDictionary(PdfWriter writer)
 {
     return(PdfNumberTree.WriteTree(map, writer));
 }