GetAsName() public method

public GetAsName ( PdfName key ) : PdfName
key PdfName
return PdfName
示例#1
1
 /**
 * Processes a dictionary.
 * In case of font dictionaries, the dictionary is processed.
 */
 public void UnembedTTF(PdfDictionary dict)
 {
     // we ignore all dictionaries that aren't font dictionaries
     if (!dict.IsFont())
         return;
     // we only remove TTF fonts
     if (dict.GetAsDict(PdfName.FONTFILE2) != null)
     {
         return;
     }
     // check if a subset was used (in which case we remove the prefix)
     PdfName baseFont = dict.GetAsName(PdfName.BASEFONT);
     if (baseFont.GetBytes()[7] == '+')
     {
         baseFont = new PdfName(baseFont.ToString().Substring(8));
         dict.Put(PdfName.BASEFONT, baseFont);
     }
     // we check if there's a font descriptor
     PdfDictionary fontDescriptor = dict.GetAsDict(PdfName.FONTDESCRIPTOR);
     if (fontDescriptor == null)
         return;
     // is there is, we replace the fontname and remove the font file
     fontDescriptor.Put(PdfName.FONTNAME, baseFont);
     fontDescriptor.Remove(PdfName.FONTFILE2);
 }
示例#2
0
 /** Creates a new instance of DocumentFont */
 internal DocumentFont(PRIndirectReference refFont) {
     encoding = "";
     fontSpecific = false;
     this.refFont = refFont;
     fontType = FONT_TYPE_DOCUMENT;
     font = (PdfDictionary)PdfReader.GetPdfObject(refFont);
     PdfName baseFont = font.GetAsName(PdfName.BASEFONT);
     fontName = baseFont != null ? PdfName.DecodeName(baseFont.ToString()) : "Unspecified Font Name";
     PdfName subType = font.GetAsName(PdfName.SUBTYPE);
     if (PdfName.TYPE1.Equals(subType) || PdfName.TRUETYPE.Equals(subType))
         DoType1TT();
     else {
         for (int k = 0; k < cjkNames.Length; ++k) {
             if (fontName.StartsWith(cjkNames[k])) {
                 fontName = cjkNames[k];
                 cjkMirror = BaseFont.CreateFont(fontName, cjkEncs[k], false);
                 return;
             }
         }
         PdfName encodingName = font.GetAsName(PdfName.ENCODING);
         if (encodingName != null){
             String enc = PdfName.DecodeName(encodingName.ToString());
             for (int k = 0; k < cjkEncs2.Length; ++k) {
                 if (enc.StartsWith(cjkEncs2[k])) {
                     if (k > 3)
                         k -= 4;
                     cjkMirror = BaseFont.CreateFont(cjkNames2[k], cjkEncs2[k], false);
                     return;
                 }
             }
             if (PdfName.TYPE0.Equals(subType) && enc.Equals("Identity-H")) {
                 ProcessType0(font);
                 isType0 = true;
             }
         }
     }
 }
 internal PdfAppearance GetAppearance(PdfDictionary merged, String text, String fieldName)
 {
     topFirst = 0;
     TextField tx = null;
     if (fieldCache == null || !fieldCache.ContainsKey(fieldName)) {
         tx = new TextField(writer, null, null);
         tx.SetExtraMargin(extraMarginLeft, extraMarginTop);
         tx.BorderWidth = 0;
         tx.SubstitutionFonts = substitutionFonts;
         DecodeGenericDictionary(merged, tx);
         //rect
         PdfArray rect = merged.GetAsArray(PdfName.RECT);
         Rectangle box = PdfReader.GetNormalizedRectangle(rect);
         if (tx.Rotation == 90 || tx.Rotation == 270)
             box = box.Rotate();
         tx.Box = box;
         if (fieldCache != null)
             fieldCache[fieldName] = tx;
     }
     else {
         tx = (TextField)fieldCache[fieldName];
         tx.Writer = writer;
     }
     PdfName fieldType = merged.GetAsName(PdfName.FT);
     if (PdfName.TX.Equals(fieldType)) {
         tx.Text = text;
         return tx.GetAppearance();
     }
     if (!PdfName.CH.Equals(fieldType))
         throw new DocumentException("An appearance was requested without a variable text field.");
     PdfArray opt = merged.GetAsArray(PdfName.OPT);
     int flags = 0;
     PdfNumber nfl = merged.GetAsNumber(PdfName.FF);
     if (nfl != null)
         flags = nfl.IntValue;
     if ((flags & PdfFormField.FF_COMBO) != 0 && opt == null) {
         tx.Text = text;
         return tx.GetAppearance();
     }
     if (opt != null) {
         String[] choices = new String[opt.Size];
         String[] choicesExp = new String[opt.Size];
         for (int k = 0; k < opt.Size; ++k) {
             PdfObject obj = opt[k];
             if (obj.IsString()) {
                     choices[k] = choicesExp[k] = ((PdfString)obj).ToUnicodeString();
             }
             else {
                 PdfArray a = (PdfArray) obj;
                 choicesExp[k] = a.GetAsString(0).ToUnicodeString();
                 choices[k] = a.GetAsString(1).ToUnicodeString();
             }
         }
         if ((flags & PdfFormField.FF_COMBO) != 0) {
             for (int k = 0; k < choices.Length; ++k) {
                 if (text.Equals(choicesExp[k])) {
                     text = choices[k];
                     break;
                 }
             }
             tx.Text = text;
             return tx.GetAppearance();
         }
         int idx = 0;
         for (int k = 0; k < choicesExp.Length; ++k) {
             if (text.Equals(choicesExp[k])) {
                 idx = k;
                 break;
             }
         }
         tx.Choices = choices;
         tx.ChoiceExports = choicesExp;
         tx.ChoiceSelection = idx;
     }
     PdfAppearance app = tx.GetListAppearance();
     topFirst = tx.TopFirst;
     return app;
 }
示例#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) {
            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));
        }
示例#5
0
        /**
        * Translate a PRDictionary to a PdfDictionary. Also translate all of the
        * objects contained in it.
        */
        protected PdfDictionary CopyDictionary(PdfDictionary inp, bool keepStruct, bool directRootKids) {
            PdfDictionary outp = new PdfDictionary();
            PdfObject type = PdfReader.GetPdfObjectRelease(inp.Get(PdfName.TYPE));
            
             if (keepStruct)
            {
                if ((directRootKids) && (inp.Contains(PdfName.PG)))
                {
                    PdfObject curr = inp;
                    disableIndirects.Add(curr);
                    while (parentObjects.ContainsKey(curr) && !(disableIndirects.Contains(curr))) {
                        curr = parentObjects[curr];
                        disableIndirects.Add(curr);
                    }
                    return null;
                }
                    
                PdfName structType = inp.GetAsName(PdfName.S);
                structTreeController.AddRole(structType);
                structTreeController.AddClass(inp);
            }

            if (structTreeController != null && structTreeController.reader != null && (inp.Contains(PdfName.STRUCTPARENTS) || inp.Contains(PdfName.STRUCTPARENT))) {
                PdfName key = PdfName.STRUCTPARENT;
                if (inp.Contains(PdfName.STRUCTPARENTS)) {
                    key = PdfName.STRUCTPARENTS;
                }
                PdfObject value = inp.Get(key);
                outp.Put(key, new PdfNumber(currentStructArrayNumber));
                structTreeController.CopyStructTreeForPage((PdfNumber) value, currentStructArrayNumber++);
            }

            foreach (PdfName key in inp.Keys) {
                PdfObject value = inp.Get(key);
                if (structTreeController != null && structTreeController.reader != null &&
                    (key.Equals(PdfName.STRUCTPARENTS) || key.Equals(PdfName.STRUCTPARENT))) {
                    continue;
                }
                if (PdfName.PAGE.Equals(type))
                {
                    if (!key.Equals(PdfName.B) && !key.Equals(PdfName.PARENT))
                    {
                        parentObjects[value] = inp;
                        PdfObject res = CopyObject(value, keepStruct, directRootKids);
                        if ((res != null) && !(res is PdfNull))
                            outp.Put(key, res);
                    }
                }
                else
                {
                    PdfObject res;
                    if (tagged && value.IsIndirect() && IsStructTreeRootReference((PRIndirectReference) value))
                        res = structureTreeRoot.Reference;
                    else
                        res = CopyObject(value, keepStruct, directRootKids);
                    if ((res != null) && !(res is PdfNull))
                        outp.Put(key, res);
                }
            }
            return outp;
        }
示例#6
0
 virtual 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 {
                 PdfDictionary field = (PdfDictionary) list[0];
                 PdfName v = field.GetAsName(PdfName.V);
                 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);
                     if (PdfCopy.IsCheckButton(field)) {
                         PdfName _as = widget.GetAsName(PdfName.AS);
                         if (v != null && _as != null)
                             widget.Put(PdfName.AS, v);
                     } else if (PdfCopy.IsRadioButton(field)) {
                         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));
                             }
                         }
                     }
                     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;
 }
        /**
         * Computes the number of unfiltered bytes that each row of the image will contain.
         * If the number of bytes results in a partial terminating byte, this number is rounded up
         * per the PDF specification
         * @param imageDictionary the dictionary of the inline image
         * @return the number of bytes per row of the image
         */
        private static int ComputeBytesPerRow(PdfDictionary imageDictionary, PdfDictionary colorSpaceDic)
        {
            PdfNumber wObj = imageDictionary.GetAsNumber(PdfName.WIDTH);
            PdfNumber bpcObj = imageDictionary.GetAsNumber(PdfName.BITSPERCOMPONENT);
            int cpp = GetComponentsPerPixel(imageDictionary.GetAsName(PdfName.COLORSPACE), colorSpaceDic);

            int w = wObj.IntValue;
            int bpc = bpcObj != null ? bpcObj.IntValue : 1;

            int bytesPerRow = (w * bpc * cpp + 7) / 8;

            return bytesPerRow;
        }
示例#8
0
        /** Creates a new instance of DocumentFont */
        internal DocumentFont(PRIndirectReference refFont, PdfDictionary drEncoding) {
        this.refFont = refFont;
        font = (PdfDictionary) PdfReader.GetPdfObject(refFont);
        if (font.GetAsName(PdfName.ENCODING) == null
                && drEncoding != null) {
            foreach (PdfName key in drEncoding.Keys) {
                font.Put(PdfName.ENCODING, drEncoding.Get(key));
            }
        }

        Init();
    }
示例#9
0
 internal static bool IsTextField(PdfDictionary field) {
     PdfName type = field.GetAsName(PdfName.FT);
     return PdfName.TX.Equals(type);
 }
示例#10
0
 internal static int? GetFlags(PdfDictionary field) {
     PdfName type = field.GetAsName(PdfName.FT);
     if (!PdfName.BTN.Equals(type))
         return null;
     PdfNumber flags = field.GetAsNumber(PdfName.FF);
     if (flags == null)
         return null;
     return flags.IntValue;
 }
示例#11
0
        private void Init()
        {
            encoding     = "";
            fontSpecific = false;
            fontType     = FONT_TYPE_DOCUMENT;
            PdfName baseFont = font.GetAsName(PdfName.BASEFONT);

            fontName = baseFont != null?PdfName.DecodeName(baseFont.ToString()) : "Unspecified Font Name";

            PdfName subType = font.GetAsName(PdfName.SUBTYPE);

            if (PdfName.TYPE1.Equals(subType) || PdfName.TRUETYPE.Equals(subType))
            {
                DoType1TT();
            }
            else if (PdfName.TYPE3.Equals(subType))
            {
                // In case of a Type3 font, we just show the characters as is.
                // Note that this doesn't always make sense:
                // Type 3 fonts are user defined fonts where arbitrary characters are mapped to custom glyphs
                // For instance: the character a could be mapped to an image of a dog, the character b to an image of a cat
                // When parsing a document that shows a cat and a dog, you shouldn't expect seeing a cat and a dog. Instead you'll get b and a.
                FillEncoding(null);
                FillDiffMap(font.GetAsDict(PdfName.ENCODING), null);
                FillWidths();
            }
            else
            {
                PdfName encodingName = font.GetAsName(PdfName.ENCODING);
                if (encodingName != null)
                {
                    String enc       = PdfName.DecodeName(encodingName.ToString());
                    String ffontname = CJKFont.GetCompatibleFont(enc);
                    if (ffontname != null)
                    {
                        cjkMirror   = BaseFont.CreateFont(ffontname, enc, false);
                        cjkEncoding = enc;
                        uniMap      = ((CJKFont)cjkMirror).UniMap;
                    }
                    if (PdfName.TYPE0.Equals(subType))
                    {
                        isType0 = true;
                        if (!enc.Equals("Identity-H") && cjkMirror != null)
                        {
                            PdfArray      df    = (PdfArray)PdfReader.GetPdfObjectRelease(font.Get(PdfName.DESCENDANTFONTS));
                            PdfDictionary cidft = (PdfDictionary)PdfReader.GetPdfObjectRelease(df[0]);
                            PdfNumber     dwo   = (PdfNumber)PdfReader.GetPdfObjectRelease(cidft.Get(PdfName.DW));
                            if (dwo != null)
                            {
                                defaultWidth = dwo.IntValue;
                            }
                            hMetrics = ReadWidths((PdfArray)PdfReader.GetPdfObjectRelease(cidft.Get(PdfName.W)));

                            PdfDictionary fontDesc = (PdfDictionary)PdfReader.GetPdfObjectRelease(cidft.Get(PdfName.FONTDESCRIPTOR));
                            FillFontDesc(fontDesc);
                        }
                        else
                        {
                            ProcessType0(font);
                        }
                    }
                }
            }
        }
示例#12
0
        virtual 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
                    {
                        PdfDictionary field = (PdfDictionary)list[0];
                        PdfName       v     = field.GetAsName(PdfName.V);
                        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);
                            if (PdfCopy.IsCheckButton(field))
                            {
                                PdfName _as = widget.GetAsName(PdfName.AS);
                                if (v != null && _as != null)
                                {
                                    widget.Put(PdfName.AS, v);
                                }
                            }
                            else if (PdfCopy.IsRadioButton(field))
                            {
                                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));
                                    }
                                }
                            }
                            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);
        }
示例#13
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));
        }
示例#14
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;
 }
示例#15
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.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.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;
 }