當前位置: 首頁>>代碼示例>>C#>>正文


C# PdfDictionary.MergeDifferent方法代碼示例

本文整理匯總了C#中iTextSharp.text.pdf.PdfDictionary.MergeDifferent方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfDictionary.MergeDifferent方法的具體用法?C# PdfDictionary.MergeDifferent怎麽用?C# PdfDictionary.MergeDifferent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在iTextSharp.text.pdf.PdfDictionary的用法示例。


在下文中一共展示了PdfDictionary.MergeDifferent方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: BranchForm

 protected 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);
         }
         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];
                 PdfDictionary pageDic = 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 = 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;
 }
開發者ID:,項目名稱:,代碼行數:64,代碼來源:

示例2: Fill

 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);
     }
 }
開發者ID:JamieMellway,項目名稱:iTextSharpLGPL-Monotouch,代碼行數:100,代碼來源:AcroFields.cs

示例3: Fill

 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;
     arrfds = null;
     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;
         ArrayList arr = annots.ArrayList;
         for (int j = 0; j < arr.Count; ++j) {
             PdfObject annoto = PdfReader.GetPdfObject((PdfObject)arr[j], annots);
             if (!(annoto is PdfDictionary)) {
                 PdfReader.ReleaseLastXrefPartial((PdfObject)arr[j]);
                 continue;
             }
             PdfDictionary annot = (PdfDictionary)annoto;
             if (!PdfName.WIDGET.Equals(annot.Get(PdfName.SUBTYPE))) {
                 PdfReader.ReleaseLastXrefPartial((PdfObject)arr[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 = (PdfString)PdfReader.GetPdfObject(annot.Get(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 = (PdfDictionary)PdfReader.GetPdfObject(annot.Get(PdfName.PARENT), annot);
             }
             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.values.Add(widget);
             else
                 item.values.Add(value);
             item.widgets.Add(widget);
             item.widget_refs.Add(arr[j]); // must be a reference
             if (top != null)
                 dic.MergeDifferent(top);
             item.merged.Add(dic);
             item.page.Add(k);
             item.tabOrder.Add(j);
         }
     }
 }
開發者ID:hjgode,項目名稱:iTextSharpCF,代碼行數:68,代碼來源:AcroFields.cs

示例4: BranchForm

 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.Get(PdfName.AP);
                         if (v != null && ap != null) {
                             if (!mergedTextFields.ContainsKey(list)) {
                                 mergedTextFields[list] = ap;
                             } else {
                                 PdfObject ap1 = mergedTextFields[list];
                                 widget.Put(PdfName.AP, CopyObject(ap1));
                             }
                         }
                     } 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.ContainsKey(list)) {
                                 mergedRadioButtons[list] = null;
                                 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;
 }
開發者ID:jagruti23,項目名稱:itextsharp,代碼行數:83,代碼來源:PdfCopy.cs

示例5: BranchForm

 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;
 }
開發者ID:joshaxey,項目名稱:Simple-PDFMerge,代碼行數:95,代碼來源:PdfCopy.cs


注:本文中的iTextSharp.text.pdf.PdfDictionary.MergeDifferent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。