Пример #1
0
 internal void Fill()
 {
     fields = new Hashtable();
     PdfDictionary top = (PdfDictionary)PdfReader.GetPdfObjectRelease(reader.Catalog.Get(PdfName.ACROFORM));
     if (top == null)
         return;
     PdfArray arrfds = (PdfArray)PdfReader.GetPdfObjectRelease(top.Get(PdfName.FIELDS));
     if (arrfds == null || arrfds.Size == 0)
         return;
     for (int k = 1; k <= reader.NumberOfPages; ++k) {
         PdfDictionary page = reader.GetPageNRelease(k);
         PdfArray annots = (PdfArray)PdfReader.GetPdfObjectRelease(page.Get(PdfName.ANNOTS), page);
         if (annots == null)
             continue;
         for (int j = 0; j < annots.Size; ++j) {
             PdfDictionary annot = annots.GetAsDict(j);
             if (annot == null) {
                 PdfReader.ReleaseLastXrefPartial(annots.GetAsIndirectObject(j));
                 continue;
             }
             if (!PdfName.WIDGET.Equals(annot.GetAsName(PdfName.SUBTYPE))) {
                 PdfReader.ReleaseLastXrefPartial(annots.GetAsIndirectObject(j));
                 continue;
             }
             PdfDictionary widget = annot;
             PdfDictionary dic = new PdfDictionary();
             dic.Merge(annot);
             String name = "";
             PdfDictionary value = null;
             PdfObject lastV = null;
             while (annot != null) {
                 dic.MergeDifferent(annot);
                 PdfString t = annot.GetAsString(PdfName.T);
                 if (t != null)
                     name = t.ToUnicodeString() + "." + name;
                 if (lastV == null && annot.Get(PdfName.V) != null)
                     lastV = PdfReader.GetPdfObjectRelease(annot.Get(PdfName.V));
                 if (value == null &&  t != null) {
                     value = annot;
                     if (annot.Get(PdfName.V) == null && lastV  != null)
                         value.Put(PdfName.V, lastV);
                 }
                 annot = annot.GetAsDict(PdfName.PARENT);
             }
             if (name.Length > 0)
                 name = name.Substring(0, name.Length - 1);
             Item item = (Item)fields[name];
             if (item == null) {
                 item = new Item();
                 fields[name] = item;
             }
             if (value == null)
                 item.AddValue(widget);
             else
                 item.AddValue(value);
             item.AddWidget(widget);
             item.AddWidgetRef(annots.GetAsIndirectObject(j)); // must be a reference
             if (top != null)
                 dic.MergeDifferent(top);
             item.AddMerged(dic);
             item.AddPage(k);
             item.AddTabOrder(j);
         }
     }
     // some tools produce invisible signatures without an entry in the page annotation array
     // look for a single level annotation
     PdfNumber sigFlags = top.GetAsNumber(PdfName.SIGFLAGS);
     if (sigFlags == null || (sigFlags.IntValue & 1) != 1)
         return;
     for (int j = 0; j < arrfds.Size; ++j) {
         PdfDictionary annot = arrfds.GetAsDict(j);
         if (annot == null) {
             PdfReader.ReleaseLastXrefPartial(arrfds.GetAsIndirectObject(j));
             continue;
         }
         if (!PdfName.WIDGET.Equals(annot.GetAsName(PdfName.SUBTYPE))) {
             PdfReader.ReleaseLastXrefPartial(arrfds.GetAsIndirectObject(j));
             continue;
         }
         PdfArray kids = (PdfArray)PdfReader.GetPdfObjectRelease(annot.Get(PdfName.KIDS));
         if (kids != null)
             continue;
         PdfDictionary dic = new PdfDictionary();
         dic.Merge(annot);
         PdfString t = annot.GetAsString(PdfName.T);
         if (t == null)
             continue;
         String name = t.ToUnicodeString();
         if (fields.ContainsKey(name))
             continue;
         Item item = new Item();
         fields[name] = item;
         item.AddValue(dic);
         item.AddWidget(dic);
         item.AddWidgetRef(arrfds.GetAsIndirectObject(j)); // must be a reference
         item.AddMerged(dic);
         item.AddPage(-1);
         item.AddTabOrder(-1);
     }
 }
Пример #2
0
 protected PdfArray BranchForm(Hashtable level, PdfIndirectReference parent, String fname)
 {
     PdfArray arr = new PdfArray();
     foreach (DictionaryEntry entry in level) {
         String name = (String)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 Hashtable) {
             dic.Put(PdfName.KIDS, BranchForm((Hashtable)obj, ind, fname2));
             arr.Add(ind);
             AddToBody(dic, ind);
         }
         else {
             ArrayList list = (ArrayList)obj;
             dic.MergeDifferent((PdfDictionary)list[0]);
             if (list.Count == 3) {
                 dic.MergeDifferent((PdfDictionary)list[2]);
                 int page = (int)list[1];
                 PdfDictionary pageDic = (PdfDictionary)pageDics[page - 1];
                 PdfArray annots = pageDic.GetAsArray(PdfName.ANNOTS);
                 if (annots == null) {
                     annots = new PdfArray();
                     pageDic.Put(PdfName.ANNOTS, annots);
                 }
                 PdfNumber nn = (PdfNumber)dic.Get(iTextTag);
                 dic.Remove(iTextTag);
                 AdjustTabOrder(annots, ind, nn);
             }
             else {
                 PdfArray kids = new PdfArray();
                 for (int k = 1; k < list.Count; k += 2) {
                     int page = (int)list[k];
                     PdfDictionary pageDic = (PdfDictionary)pageDics[page - 1];
                     PdfArray annots = pageDic.GetAsArray(PdfName.ANNOTS);
                     if (annots == null) {
                         annots = new PdfArray();
                         pageDic.Put(PdfName.ANNOTS, annots);
                     }
                     PdfDictionary widget = new PdfDictionary();
                     widget.Merge((PdfDictionary)list[k + 1]);
                     widget.Put(PdfName.PARENT, ind);
                     PdfNumber nn = (PdfNumber)widget.Get(iTextTag);
                     widget.Remove(iTextTag);
                     PdfIndirectReference wref = AddToBody(widget).IndirectReference;
                     AdjustTabOrder(annots, wref, nn);
                     kids.Add(wref);
                     Propagate(widget, null, false);
                 }
                 dic.Put(PdfName.KIDS, kids);
             }
             arr.Add(ind);
             AddToBody(dic, ind);
             Propagate(dic, null, false);
         }
     }
     return arr;
 }
Пример #3
0
        protected PdfArray BranchForm(Hashtable level, PdfIndirectReference parent, String fname)
        {
            PdfArray arr = new PdfArray();

            foreach (DictionaryEntry entry in level)
            {
                String name = (String)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 Hashtable)
                {
                    dic.Put(PdfName.KIDS, BranchForm((Hashtable)obj, ind, fname2));
                    arr.Add(ind);
                    AddToBody(dic, ind);
                }
                else
                {
                    ArrayList list = (ArrayList)obj;
                    dic.MergeDifferent((PdfDictionary)list[0]);
                    if (list.Count == 3)
                    {
                        dic.MergeDifferent((PdfDictionary)list[2]);
                        int           page    = (int)list[1];
                        PdfDictionary pageDic = (PdfDictionary)pageDics[page - 1];
                        PdfArray      annots  = pageDic.GetAsArray(PdfName.ANNOTS);
                        if (annots == null)
                        {
                            annots = new PdfArray();
                            pageDic.Put(PdfName.ANNOTS, annots);
                        }
                        PdfNumber nn = (PdfNumber)dic.Get(iTextTag);
                        dic.Remove(iTextTag);
                        AdjustTabOrder(annots, ind, nn);
                    }
                    else
                    {
                        PdfArray kids = new PdfArray();
                        for (int k = 1; k < list.Count; k += 2)
                        {
                            int           page    = (int)list[k];
                            PdfDictionary pageDic = (PdfDictionary)pageDics[page - 1];
                            PdfArray      annots  = pageDic.GetAsArray(PdfName.ANNOTS);
                            if (annots == null)
                            {
                                annots = new PdfArray();
                                pageDic.Put(PdfName.ANNOTS, annots);
                            }
                            PdfDictionary widget = new PdfDictionary();
                            widget.Merge((PdfDictionary)list[k + 1]);
                            widget.Put(PdfName.PARENT, ind);
                            PdfNumber nn = (PdfNumber)widget.Get(iTextTag);
                            widget.Remove(iTextTag);
                            PdfIndirectReference wref = AddToBody(widget).IndirectReference;
                            AdjustTabOrder(annots, wref, nn);
                            kids.Add(wref);
                            Propagate(widget, null, false);
                        }
                        dic.Put(PdfName.KIDS, kids);
                    }
                    arr.Add(ind);
                    AddToBody(dic, ind);
                    Propagate(dic, null, false);
                }
            }
            return(arr);
        }
Пример #4
0
 internal void AddDefaultColorDiff(PdfDictionary dic)
 {
     colorDictionary.MergeDifferent(dic);
 }