GetDirectObject() публичный Метод

public GetDirectObject ( PdfName key ) : PdfObject
key PdfName
Результат PdfObject
Пример #1
0
 /**
  * Shows the detail of a dictionary.
  * @param dic   the dictionary of which you want the detail
  * @param depth the depth of the current dictionary (for nested dictionaries)
  * @return  a String representation of the dictionary
  */
 public static  String GetDictionaryDetail(PdfDictionary dic, int depth){
     StringBuilder builder = new StringBuilder();
     builder.Append('(');
     IList<PdfName> subDictionaries = new List<PdfName>();
     foreach (PdfName key in dic.Keys) {
         PdfObject val = dic.GetDirectObject(key);
         if (val.IsDictionary())
             subDictionaries.Add(key);
         builder.Append(key);
         builder.Append('=');
         builder.Append(val);
         builder.Append(", ");
     }
     builder.Length = builder.Length-2;
     builder.Append(')');
     foreach (PdfName pdfSubDictionaryName in subDictionaries) {
         builder.Append('\n');
         for (int i = 0; i < depth+1; i++){
             builder.Append('\t');
         }
         builder.Append("Subdictionary ");
         builder.Append(pdfSubDictionaryName);
         builder.Append(" = ");
         builder.Append(GetDictionaryDetail(dic.GetAsDict(pdfSubDictionaryName), depth+1));
     }
     return builder.ToString();
 }
Пример #2
0
        public override PdfObject GetDirectObject(PdfName key)
        {
            for (int index = _resourceStack.Count - 1; index >= 0; index--)
            {
                PdfDictionary subResource = _resourceStack[index];

                if (subResource != null)
                {
                    PdfObject obj = subResource.GetDirectObject(key);
                    if (obj != null)
                    {
                        return(obj);
                    }
                }
            }
            return(base.GetDirectObject(key));
        }
Пример #3
0
        /**
         * If the child of a structured element is a dictionary, we inspect the
         * child; we may also draw a tag.
         * 
         * @param k
         *            the child dictionary to inspect
         */
        public void InspectChildDictionary(PdfDictionary k) {
            if (k == null)
                return;
            PdfName s = k.GetAsName(PdfName.S);
            if (s != null) {
                String tagN = PdfName.DecodeName(s.ToString());
			    String tag = FixTagName(tagN);
                outp.Write("<");
                outp.Write(tag);
                outp.Write(">");
                PdfDictionary dict = k.GetAsDict(PdfName.PG);
                if (dict != null)
                    ParseTag(tagN, k.GetDirectObject(PdfName.K), dict);
                InspectChild(k.Get(PdfName.K));
                outp.Write("</");
                outp.Write(tag);
                outp.WriteLine(">");
            } else
                InspectChild(k.Get(PdfName.K));
        }
Пример #4
0
        /**
         * If the child of a structured element is a dictionary, we inspect the
         * child; we may also draw a tag.
         * 
         * @param k
         *            the child dictionary to inspect
         */
        public void InspectChildDictionary(PdfDictionary k, bool inspectAttributes) {
            if (k == null)
                return;
            PdfName s = k.GetAsName(PdfName.S);
            if (s != null) {
                String tagN = PdfName.DecodeName(s.ToString());
			    String tag = FixTagName(tagN);
                outp.Write("<");
                outp.Write(tag);
                if (inspectAttributes) {
                    PdfDictionary a = k.GetAsDict(PdfName.A);
                    if (a != null) {
                        Dictionary<PdfName, PdfObject>.KeyCollection keys = a.Keys;
                        foreach (PdfName key in keys) {
                            outp.Write(' ');
                            PdfObject value = a.Get(key);
                            value = PdfReader.GetPdfObject(value);
                            outp.Write(XmlName(key));
                            outp.Write("=\"");
                            outp.Write(value.ToString());
                            outp.Write("\"");
                        }
                    }
                }
                outp.Write(">");
                PdfDictionary dict = k.GetAsDict(PdfName.PG);
                if (dict != null)
                    ParseTag(tagN, k.GetDirectObject(PdfName.K), dict);
                InspectChild(k.GetDirectObject(PdfName.K));
                outp.Write("</");
                outp.Write(tag);
                outp.WriteLine(">");
            } else
                InspectChild(k.GetDirectObject(PdfName.K));
        }
Пример #5
0
 private PdfArray BranchForm(Dictionary<String, Object> level, PdfIndirectReference parent, String fname) {
     PdfArray arr = new PdfArray();
     foreach (KeyValuePair<String, Object> entry in level) {
         String name = entry.Key;
         Object obj = entry.Value;
         PdfIndirectReference ind = PdfIndirectReference;
         PdfDictionary dic = new PdfDictionary();
         if (parent != null)
             dic.Put(PdfName.PARENT, parent);
         dic.Put(PdfName.T, new PdfString(name, PdfObject.TEXT_UNICODE));
         String fname2 = fname + "." + name;
         int coidx = calculationOrder.IndexOf(fname2);
         if (coidx >= 0)
             calculationOrderRefs[coidx] = ind;
         if (obj is Dictionary<String, Object>) {
             dic.Put(PdfName.KIDS, BranchForm((Dictionary<String, Object>) obj, ind, fname2));
             arr.Add(ind);
             AddToBody(dic, ind, true);
         } else {
             List<Object> list = (List<Object>)obj;
             dic.MergeDifferent((PdfDictionary) list[0]);
             if (list.Count == 3) {
                 dic.MergeDifferent((PdfDictionary)list[2]);
                 int page = (int)list[1];
                 PdfArray annots = importedPages[page - 1].mergedFields;
                 PdfNumber nn = (PdfNumber)dic.Get(iTextTag);
                 dic.Remove(iTextTag);
                 dic.Put(PdfName.TYPE, PdfName.ANNOT);
                 AdjustTabOrder(annots, ind, nn);
             } else {
                 PdfDictionary field = (PdfDictionary)list[0];
                 PdfArray kids = new PdfArray();
                 for (int k = 1; k < list.Count; k += 2) {
                     int page = (int)list[k];
                     PdfArray annots = importedPages[page - 1].mergedFields;
                     PdfDictionary widget = new PdfDictionary();
                     widget.Merge((PdfDictionary)list[k + 1]);
                     widget.Put(PdfName.PARENT, ind);
                     PdfNumber nn = (PdfNumber)widget.Get(iTextTag);
                     widget.Remove(iTextTag);
                     if (PdfCopy.IsTextField(field)) {
                         PdfString v = field.GetAsString(PdfName.V);
                         PdfObject ap = widget.GetDirectObject(PdfName.AP);
                         if (v != null && ap != null) {
                             if (!mergedTextFields.ContainsKey(list)) {
                                 mergedTextFields[list] = v;
                             } else {
                                 try {
                                     TextField tx = new TextField(this, null, null);
                                     fields[0].DecodeGenericDictionary(widget, tx);
                                     Rectangle box =
                                         PdfReader.GetNormalizedRectangle(widget.GetAsArray(PdfName.RECT));
                                     if (tx.Rotation == 90 || tx.Rotation == 270) {
                                         box = box.Rotate();
                                     }
                                     tx.Box = box;
                                     tx.Text = mergedTextFields[list].ToUnicodeString();
                                     PdfAppearance app = tx.GetAppearance();
                                     ((PdfDictionary) ap).Put(PdfName.N, app.IndirectReference);
                                 }
                                 catch (DocumentException ex) {
                                     //do nothing
                                 }
                             }
                         }
                     } else if (PdfCopy.IsCheckButton(field)) {
                         PdfName v = field.GetAsName(PdfName.V);
                         PdfName as_ = widget.GetAsName(PdfName.AS);
                         if (v != null && as_ != null)
                             widget.Put(PdfName.AS, v);
                     } else if (PdfCopy.IsRadioButton(field)) {
                         PdfName v = field.GetAsName(PdfName.V);
                         PdfName as_ = widget.GetAsName(PdfName.AS);
                         if (v != null && as_ != null && !as_.Equals(GetOffStateName(widget))) {
                             if (!mergedRadioButtons.Contains(list)) {
                                 mergedRadioButtons.Add(list);
                                 widget.Put(PdfName.AS, v);
                             } else {
                                 widget.Put(PdfName.AS, GetOffStateName(widget));
                             }
                         }
                     }
                     widget.Put(PdfName.TYPE, PdfName.ANNOT);
                     PdfIndirectReference wref = AddToBody(widget, PdfIndirectReference, true).IndirectReference;
                     AdjustTabOrder(annots, wref, nn);
                     kids.Add(wref);
                 }
                 dic.Put(PdfName.KIDS, kids);
             }
             arr.Add(ind);
             AddToBody(dic, ind, true);
         }
     }
     return arr;
 }