コード例 #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)
                {
                    PdfArray array = (PdfArray)item;
                    if (array.Elements.Count != 0)
                    {
                        return(array.Elements[0].ToString());
                    }
                }
            }
            return("");
        }
コード例 #2
0
        /// <summary>
        /// Gets the index of the specified string in the /Opt array or -1, if no such string exists.
        /// <param name="value">Value, for which the index should be retrieved</param>
        /// <param name="useExportValue">true if value is the export value, false if value is the text shown in the UI</param>
        /// </summary>
        protected int IndexInOptArray(string value, bool useExportValue)
        {
            PdfArray opt = Elements[Keys.Opt] as PdfArray;

            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)
                    {
                        PdfArray array = (PdfArray)item;
                        if (array.Elements.Count > 0)
                        {
                            // Pdf Reference 1.7, Section 12.7.4.4: Should be a 2-element Array. Second value is the text shown in the UI.
                            if ((!useExportValue && array.Elements.Count > 1 && array.Elements[1].ToString() == value) ||
                                (array.Elements.Count > 0 && array.Elements[0].ToString() == value))
                            {
                                return(idx);
                            }
                        }
                    }
                }
            }
            return(-1);
        }
コード例 #3
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[Keys.Opt] as PdfArray;

            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)
                    {
                        PdfArray array = (PdfArray)item;
                        if (array.Elements.Count != 0)
                        {
                            if (array.Elements[idx].ToString() == value)
                            {
                                return(idx);
                            }
                        }
                    }
                }
            }
            return(-1);
        }
コード例 #4
0
ファイル: PdfTextField.cs プロジェクト: mapilab/PDFsharp
        internal XStringFormat GetAlignment(DictionaryElements dict)
        {
            PdfItem item = dict.GetValue("/Q");

            if (item != null)
            {
                int alignment = Int32.Parse(item.ToString());

                switch (alignment)
                {
                case 0:
                    return(XStringFormats.TopLeft);

                case 1:
                    return(XStringFormats.TopCenter);

                case 2:
                    return(XStringFormats.TopRight);

                default:
                    return(XStringFormats.TopLeft);
                }
            }
            else
            {
                return(XStringFormats.TopLeft);
            }
        }
コード例 #5
0
 /// <summary>
 /// Decodes the data with the specified filter.
 /// </summary>
 public static byte[] Decode(byte[] data, PdfItem filterItem)
 {
     byte[] result = null;
     if (filterItem is PdfReference)
     {
         PdfReference iref = (PdfReference)filterItem;
         Debug.Assert(iref.Value != null, "Indirect /Filter value is null");
         filterItem = iref.Value;
     }
     if (filterItem is PdfName)
     {
         Filter filter = GetFilter(filterItem.ToString());
         if (filter != null)
         {
             result = filter.Decode(data);
         }
     }
     else if (filterItem is PdfArray)
     {
         PdfArray array = (PdfArray)filterItem;
         foreach (PdfItem item in array)
         {
             data = Decode(data, item);
         }
         result = data;
     }
     return(result);
 }
コード例 #6
0
        /// <summary>
        /// Gets the value or the display text from the index in the /Opt array.
        /// <param name="index">Index of the value that should be retrieved</param>
        /// <param name="useExportValue">true to get the export value, false to get the text shown in the UI</param>
        /// </summary>
        protected string ValueInOptArray(int index, bool useExportValue)
        {
            PdfArray opt = Elements[Keys.Opt] as PdfArray;

            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());
                }
                else if (item is PdfArray)
                {
                    PdfArray array = (PdfArray)item;
                    return(!useExportValue && array.Elements.Count > 1 ? array.Elements[1].ToString() : array.Elements[0].ToString());
                }
            }
            return("");
        }
コード例 #7
0
 /// <summary>
 /// Decodes the data with the specified filter.
 /// </summary>
 public static byte[] Decode(byte[] data, PdfItem filterItem, PdfItem decodeParms)
 {
     byte[] result = null;
     if (filterItem is PdfName && (decodeParms == null || decodeParms is PdfDictionary))
     {
         Filter filter = GetFilter(filterItem.ToString());
         if (filter != null)
         {
             result = filter.Decode(data, decodeParms as PdfDictionary);
         }
     }
     else if (filterItem is PdfArray itemArray && (decodeParms == null || decodeParms is PdfArray))
     {
         var decodeArray = decodeParms as PdfArray;
         // array length of filter and decode parms should match. if they dont, return data unmodified
         if (decodeArray != null && decodeArray.Elements.Count != itemArray.Elements.Count)
         {
             return(data);
         }
         for (var i = 0; i < itemArray.Elements.Count; i++)
         {
             var item  = itemArray.Elements[i];
             var parms = decodeArray != null ? decodeArray.Elements[i] : null;
             data = Decode(data, item, parms);
         }
         result = data;
     }
     return(result);
 }
コード例 #8
0
        internal override void SetObject(PdfItem obj)
        {
            PdfDictionary dict = (PdfDictionary)obj;

            if (PdfInternals.GetObjectID(dict).IsEmpty)
            {
                this.tbxObjectID.Text = "«direct»";
            }
            else
            {
                this.tbxObjectID.Text = PdfInternals.GetObjectID(dict).ToString();
            }
            this.txtType.Text = dict.GetType().Name;

            this.lvKeys.Items.Clear();
            this.tbxStream.Clear();
            PdfName[] keys = dict.Elements.KeyNames;
            foreach (PdfName key in keys)
            {
                bool    indirect = false;
                PdfItem tag      = null;
                PdfItem value    = dict.Elements[key];
                if (value == null)
                {
                    throw new NotImplementedException("Value is null.");
                }
                else if (value is PdfReference)
                {
                    indirect = true;
                    value    = ((PdfReference)value).Value;
                    tag      = value;
                }
                else
                {
                    if (value is PdfObject)
                    {
                        tag = value;
                    }
                }

                string address = "";
                if (indirect)
                {
                    address = /*((PdfObject)value).ObjectID.ToString() +*/ "---> ";
                }
                ListViewItem item = new ListViewItem(
                    new string[4] {
                    key.Value,
                    address + value.ToString(),
                    indirect ? PdfInternals.GetObjectID((PdfObject)value).ToString() : "",
                    value.GetType().Name
                });
                item.Tag = tag;
                this.lvKeys.Items.Add(item);
            }

            FillStreamBox();
        }
コード例 #9
0
ファイル: ArrayPage.cs プロジェクト: jgshumate1/Migradoc
        internal override void SetObject(PdfItem obj)
        {
            PdfArray array = (PdfArray)obj;

            if (PdfInternals.GetObjectID(array).IsEmpty)
            {
                this.tbxObjectID.Text = "«direct»";
            }
            else
            {
                this.tbxObjectID.Text = PdfInternals.GetObjectID(array).ToString();
            }
            this.txtType.Text = array.GetType().Name;

            this.lvItems.Items.Clear();
            PdfItem[] items = array.Elements.Items;
            int       count = items.Length;

            for (int idx = 0; idx < count; idx++)
            {
                bool    indirect = false;
                PdfItem tag      = null;
                PdfItem value    = items[idx];
                if (value == null)
                {
                    throw new NotImplementedException("Value is null.");
                }
                else if (value is PdfReference)
                {
                    indirect = true;
                    value    = ((PdfReference)value).Value;
                    tag      = value;
                }
                else
                {
                    if (value is PdfObject)
                    {
                        tag = value;
                    }
                }

                string address = "";
                if (indirect)
                {
                    address = /*((PdfObject)value).ObjectID.ToString() +*/ "---> ";
                }
                ListViewItem item = new ListViewItem(
                    new string[4] {
                    idx.ToString(),
                    address + value.ToString(),
                    indirect ? PdfInternals.GetObjectID((PdfObject)value).ToString() : "",
                    value.GetType().Name
                });
                item.Tag = tag;
                this.lvItems.Items.Add(item);
            }
        }
コード例 #10
0
        internal override void SetObject(PdfItem value)
        {
            PdfObject obj = (PdfObject)value;

            this.tbxObjectID.Text = PdfInternals.GetObjectID(obj).ToString();
            this.txtType.Text     = obj.GetType().Name;

            this.lvKeys.Items.Clear();

            ListViewItem item = new ListViewItem(
                new string[3] {
                ExplorerProcess.GetTypeName(obj), value.ToString(), value.GetType().Name
            });

            this.lvKeys.Items.Add(item);
        }
コード例 #11
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)
                    {
                        PdfArray array = (PdfArray)item;
                        if (array.Elements.Count != 0)
                        {
                            if (array.Elements[0].ToString() == value)
                            {
                                return(idx);
                            }
                        }
                    }
                }
            }
            return(-1);
        }
コード例 #12
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, bool useExportValue)
        {
            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)
                    {
                        PdfArray array = (PdfArray)item;
                        // Pdf Reference 1.7, Section 12.7.4.4: Should be a 2-element Array. Second value is the text shown in the UI.
                        if ((!useExportValue && array.Elements.Count > 1 && array.Elements[1].ToString() == value) ||
                            (array.Elements.Count > 0 && array.Elements[0].ToString() == value))
                        {
                            return(idx);
                        }
                    }
                }
            }
            return(-1);
        }
コード例 #13
0
        int IndexInOptStrings(string value)
        {
            PdfArray opt = Elements[Keys.Opt] as PdfArray;

            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);
                        }
                    }
                }
            }
            return(-1);
        }
コード例 #14
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)
     {
         PdfArray array = (PdfArray)filterItem;
         foreach (PdfItem item in array)
         {
             data = Decode(data, item);
         }
         result = data;
     }
     return(result);
 }
コード例 #15
0
            public Font(PdfDictionary dictionary)
            {
                font = dictionary;

                // font.Elements["SubType"]
                // font.Elements["Encoding"]
                if (font.Elements.Keys.Contains("/Encoding"))
                {
                    PdfItem item = font.Elements["/Encoding"];
                    if (item is PdfReference)
                    {
                        var dict = (((item as PdfReference).Value) as PdfDictionary);
                        if (dict.Elements.ContainsKey("/BaseEncoding"))
                        {
                            Encoding = dict.Elements["/BaseEncoding"].ToString();
                        }
                    }
                    else
                    {
                        Encoding = item.ToString();
                    }
                }

                if (Encoding != null && Encoding.StartsWith("/Identity-"))
                {
                    IsTwoByte = true;
                }

                if (font.Elements.Keys.Contains("/Subtype"))
                {
                    switch (font.Elements["/Subtype"].ToString())
                    {
                    case "/TrueType":
                        Type = font_type.TrueType;
                        break;

                    case "/Type0":
                        Type = font_type.Type0;
                        break;

                    case "/Type1":
                        Type = font_type.Type1;
                        break;

                    case "/Type3":
                        Type = font_type.Type3;
                        break;

                    default:
                        Type = font_type.Other;
                        break;
                    }
                }

                if (font.Elements.ContainsKey("/FontDescriptor"))
                {
                    var obj = font.Elements["/FontDescriptor"];
                    if (obj is PdfReference)
                    {
                        obj = (obj as PdfReference).Value;
                    }
                    obj = (obj as PdfDictionary).Elements["/Flags"];
                    if (obj != null)
                    {
                        if (obj is PdfReference)
                        {
                            obj = (obj as PdfReference).Value;
                        }
                        if (obj is PdfInteger)
                        {
                            Flags = (obj as PdfInteger).Value;
                        }
                    }
                }

                if (font.Elements.Keys.Contains("/ToUnicode"))
                { // parse to unicode
                    PdfItem item = font.Elements["/ToUnicode"];
                    if (item is PdfReference)
                    {
                        item = (item as PdfReference).Value;
                    }
                    if (item is PdfDictionary)
                    {
                        string map = (item as PdfDictionary).Stream.ToString();
                        toUnicode = ParseCMap(map);
                    }
                }
                else
                {
                    if (Encoding != null)
                    {
                        switch (Encoding)
                        {
                        case "/MacRomanEncoding":
                            toUnicode = EncodingTables.MacRoman;
                            break;

                        case "/WinAnsiEncoding":
                            toUnicode = EncodingTables.WinAnsi;
                            break;

                        case "/MacExpertEncoding":
                            toUnicode = EncodingTables.MacExpert;
                            break;

                        case "/Standard":
                            toUnicode = EncodingTables.Standard;
                            break;

                        case "/Symbol":
                            toUnicode = EncodingTables.Symbol;
                            break;
                        }
                    }
                    else
                    {
                        if ((Flags & Flag_Symbolic) != 0)
                        {
                            toUnicode = EncodingTables.Symbol;
                        }
                        else
                        {
                            toUnicode = EncodingTables.Standard;
                        }
                    }
                }
            }
コード例 #16
0
ファイル: Filtering.cs プロジェクト: dankennedy/PDFSharp
 /// <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)
   {
     PdfArray array = (PdfArray)filterItem;
     foreach (PdfItem item in array)
       data = Filtering.Decode(data, item);
     result = data;
   }
   return result;
 }