/**
 * 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];
     Dictionary<int, PdfObject> 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(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];
             }
             else {
                 type = 'e';
             }
         }
         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;
         case 'e':
             labelstrings[i] = prefix;
             break;
         }
         pagecount++;
     }
     return labelstrings;
 }
Esempio n. 2
0
        /**
         *
         * @param result
         * @param itemNr
         * @param listLevel
         * @throws IOException
         * @since 2.1.3
         */
        protected void WriteListTextBlock(Stream result, int itemNr, RtfListLevel listLevel)
        {
            byte[] t;
            result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length);
            result.Write(RtfList.LIST_TEXT, 0, RtfList.LIST_TEXT.Length);
            result.Write(RtfParagraph.PARAGRAPH_DEFAULTS, 0, RtfParagraph.PARAGRAPH_DEFAULTS.Length);
            if (this.inTable)
            {
                result.Write(RtfParagraph.IN_TABLE, 0, RtfParagraph.IN_TABLE.Length);
            }
            result.Write(RtfFontList.FONT_NUMBER, 0, RtfFontList.FONT_NUMBER.Length);
            if (listLevel.GetListType() != RtfListLevel.LIST_TYPE_BULLET)
            {
                result.Write(t = IntToByteArray(listLevel.GetFontNumber().GetFontNumber()), 0, t.Length);
            }
            else
            {
                result.Write(t = IntToByteArray(listLevel.GetFontBullet().GetFontNumber()), 0, t.Length);
            }
            listLevel.WriteIndentation(result);
            result.Write(DELIMITER, 0, DELIMITER.Length);
            if (listLevel.GetListType() != RtfListLevel.LIST_TYPE_BULLET)
            {
                switch (listLevel.GetListType())
                {
                case RtfListLevel.LIST_TYPE_NUMBERED: result.Write(t = IntToByteArray(itemNr), 0, t.Length); break;

                case RtfListLevel.LIST_TYPE_UPPER_LETTERS: result.Write(t = DocWriter.GetISOBytes(RomanAlphabetFactory.GetUpperCaseString(itemNr)), 0, t.Length); break;

                case RtfListLevel.LIST_TYPE_LOWER_LETTERS: result.Write(t = DocWriter.GetISOBytes(RomanAlphabetFactory.GetLowerCaseString(itemNr)), 0, t.Length); break;

                case RtfListLevel.LIST_TYPE_UPPER_ROMAN: result.Write(t = DocWriter.GetISOBytes(RomanNumberFactory.GetUpperCaseString(itemNr)), 0, t.Length); break;

                case RtfListLevel.LIST_TYPE_LOWER_ROMAN: result.Write(t = DocWriter.GetISOBytes(RomanNumberFactory.GetLowerCaseString(itemNr)), 0, t.Length); break;
                }
                result.Write(LIST_NUMBER_END, 0, LIST_NUMBER_END.Length);
            }
            else
            {
                this.document.FilterSpecialChar(result, listLevel.GetBulletCharacter(), true, false);
            }
            result.Write(TAB, 0, TAB.Length);
            result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length);
        }
Esempio n. 3
0
        /// <summary>
        /// @throws IOException
        /// @since 2.1.3
        /// </summary>
        /// <param name="result"></param>
        /// <param name="itemNr"></param>
        /// <param name="listLevel"></param>
        protected void WriteListTextBlock(Stream result, int itemNr, RtfListLevel listLevel)
        {
            byte[] t;
            result.Write(OpenGroup, 0, OpenGroup.Length);
            result.Write(ListText, 0, ListText.Length);
            result.Write(RtfPhrase.ParagraphDefaults, 0, RtfPhrase.ParagraphDefaults.Length);
            if (InTable)
            {
                result.Write(RtfPhrase.InTable, 0, RtfPhrase.InTable.Length);
            }
            result.Write(RtfFontList.FontNumber, 0, RtfFontList.FontNumber.Length);
            if (listLevel.GetListType() != RtfListLevel.LIST_TYPE_BULLET)
            {
                result.Write(t = IntToByteArray(listLevel.GetFontNumber().GetFontNumber()), 0, t.Length);
            }
            else
            {
                result.Write(t = IntToByteArray(listLevel.GetFontBullet().GetFontNumber()), 0, t.Length);
            }
            listLevel.WriteIndentation(result);
            result.Write(Delimiter, 0, Delimiter.Length);
            if (listLevel.GetListType() != RtfListLevel.LIST_TYPE_BULLET)
            {
                switch (listLevel.GetListType())
                {
                case RtfListLevel.LIST_TYPE_NUMBERED: result.Write(t = IntToByteArray(itemNr), 0, t.Length); break;

                case RtfListLevel.LIST_TYPE_UPPER_LETTERS: result.Write(t = DocWriter.GetIsoBytes(RomanAlphabetFactory.GetUpperCaseString(itemNr)), 0, t.Length); break;

                case RtfListLevel.LIST_TYPE_LOWER_LETTERS: result.Write(t = DocWriter.GetIsoBytes(RomanAlphabetFactory.GetLowerCaseString(itemNr)), 0, t.Length); break;

                case RtfListLevel.LIST_TYPE_UPPER_ROMAN: result.Write(t = DocWriter.GetIsoBytes(RomanNumberFactory.GetUpperCaseString(itemNr)), 0, t.Length); break;

                case RtfListLevel.LIST_TYPE_LOWER_ROMAN: result.Write(t = DocWriter.GetIsoBytes(RomanNumberFactory.GetLowerCaseString(itemNr)), 0, t.Length); break;
                }
                result.Write(ListNumberEnd, 0, ListNumberEnd.Length);
            }
            else
            {
                Document.FilterSpecialChar(result, listLevel.GetBulletCharacter(), true, false);
            }
            result.Write(Tab, 0, Tab.Length);
            result.Write(CloseGroup, 0, CloseGroup.Length);
        }
Esempio n. 4
0
        /// <summary>
        /// Retrieves the page labels from a PDF as an array of String objects.
        /// </summary>
        /// <param name="reader">a PdfReader object that has the page labels you want to retrieve</param>
        /// <returns>a String array or  null  if no page labels are present</returns>
        public static string[] GetPageLabels(PdfReader reader)
        {
            var n = reader.NumberOfPages;

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

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

            var labelstrings = new string[n];
            var numberTree   = PdfNumberTree.ReadTree(labels);

            var pagecount = 1;
            var prefix    = "";
            var type      = 'D';

            for (var i = 0; i < n; i++)
            {
                if (numberTree.ContainsKey(i))
                {
                    var 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);
        }