Exemple #1
0
        /// <summary>
        /// Gets the value from the index in the /Opt array.
        /// </summary>
        protected string ValueInOptArray(int index)
        {
            PDFArray opt = Elements.GetArray(Keys.Opt);

            if (opt != null)
            {
                int count = opt.Elements.Count;
                if (index < 0 || index >= count)
                {
                    throw new ArgumentOutOfRangeException("index");
                }

                PDFItem item = opt.Elements[index];
                if (item is PDFString)
                {
                    return(item.ToString());
                }

                if (item is PDFArray array)
                {
                    if (array.Elements.Count != 0)
                    {
                        return(array.Elements[0].ToString());
                    }
                }
            }
            return("");
        }
Exemple #2
0
        /// <summary>
        /// Gets the index of the specified string in the /Opt array or -1, if no such string exists.
        /// </summary>
        protected int IndexInOptArray(string value)
        {
            PDFArray opt = Elements.GetArray(Keys.Opt);

#if DEBUG  // Check with //R080317 implemention
            PDFArray opt2 = null;
            if (Elements[Keys.Opt] is PDFArray)
            {
                opt2 = Elements[Keys.Opt] as PDFArray;
            }
            else if (Elements[Keys.Opt] is Advanced.PDFReference)
            {
                //falls das Array nicht direkt am Element hängt,
                //das Array aus dem referenzierten Element holen
                opt2 = ((Advanced.PDFReference)Elements[Keys.Opt]).Value as PDFArray;
            }
            Debug.Assert(ReferenceEquals(opt, opt2));
#endif

            if (opt != null)
            {
                int count = opt.Elements.Count;
                for (int idx = 0; idx < count; idx++)
                {
                    PDFItem item = opt.Elements[idx];
                    if (item is PDFString)
                    {
                        if (item.ToString() == value)
                        {
                            return(idx);
                        }
                    }
                    else if (item is PDFArray array)
                    {
                        if (array.Elements.Count != 0)
                        {
                            if (array.Elements[0].ToString() == value)
                            {
                                return(idx);
                            }
                        }
                    }
                }
            }
            return(-1);
        }
Exemple #3
0
 /// <summary>
 /// Decodes the data with the specified filter.
 /// </summary>
 public static byte[] Decode(byte[] data, PDFItem filterItem)
 {
     byte[] result = null;
     if (filterItem is PDFName)
     {
         Filter filter = GetFilter(filterItem.ToString());
         if (filter != null)
         {
             result = filter.Decode(data);
         }
     }
     else if (filterItem is PDFArray array)
     {
         foreach (PDFItem item in array)
         {
             data = Decode(data, item);
         }
         result = data;
     }
     return(result);
 }