ToUnicodeString() 공개 메소드

public ToUnicodeString ( ) : String
리턴 String
예제 #1
0
        /** Gets the field value or <CODE>null</CODE> if the field does not
         * exist or has no value defined.
         * @param name the fully qualified field name
         * @return the field value or <CODE>null</CODE>
         */
        public String GetFieldValue(String name)
        {
            PdfDictionary field = GetField(name);

            if (field == null)
            {
                return(null);
            }
            PdfObject v = GetPdfObject(field.Get(PdfName.V));

            if (v == null)
            {
                return(null);
            }
            if (v.IsName())
            {
                return(PdfName.DecodeName(((PdfName)v).ToString()));
            }
            else if (v.IsString())
            {
                PdfString vs = (PdfString)v;
                if (encoding == null || vs.Encoding != null)
                {
                    return(vs.ToUnicodeString());
                }
                byte[] b = vs.GetBytes();
                if (b.Length >= 2 && b[0] == (byte)254 && b[1] == (byte)255)
                {
                    return(vs.ToUnicodeString());
                }
                try {
                    if (encoding.Equals(PdfName.SHIFT_JIS))
                    {
                        return(Encoding.GetEncoding(932).GetString(b));
                    }
                    else if (encoding.Equals(PdfName.UHC))
                    {
                        return(Encoding.GetEncoding(949).GetString(b));
                    }
                    else if (encoding.Equals(PdfName.GBK))
                    {
                        return(Encoding.GetEncoding(936).GetString(b));
                    }
                    else if (encoding.Equals(PdfName.BIGFIVE))
                    {
                        return(Encoding.GetEncoding(950).GetString(b));
                    }
                    else if (encoding.Equals(PdfName.UTF_8))
                    {
                        return(Encoding.UTF8.GetString(b));
                    }
                }
                catch  {
                }
                return(vs.ToUnicodeString());
            }
            return(null);
        }
예제 #2
0
        /// <summary>
        /// Gets the field value or  null  if the field does not
        /// exist or has no value defined.
        /// </summary>
        /// <param name="name">the fully qualified field name</param>
        /// <returns>the field value or  null </returns>
        public string GetFieldValue(string name)
        {
            PdfDictionary field = (PdfDictionary)fields[name];

            if (field == null)
            {
                return(null);
            }
            PdfObject v = GetPdfObject(field.Get(PdfName.V));

            if (v == null)
            {
                return(null);
            }
            if (v.IsName())
            {
                return(PdfName.DecodeName(((PdfName)v).ToString()));
            }
            else if (v.IsString())
            {
                PdfString vs = (PdfString)v;
                if (Encoding == null || vs.Encoding != null)
                {
                    return(vs.ToUnicodeString());
                }
                byte[] b = vs.GetBytes();
                if (b.Length >= 2 && b[0] == 254 && b[1] == 255)
                {
                    return(vs.ToUnicodeString());
                }
                try
                {
                    if (Encoding.Equals(PdfName.ShiftJis))
                    {
                        return(EncodingsRegistry.Instance.GetEncoding(932).GetString(b));
                    }
                    else if (Encoding.Equals(PdfName.Uhc))
                    {
                        return(EncodingsRegistry.Instance.GetEncoding(949).GetString(b));
                    }
                    else if (Encoding.Equals(PdfName.Gbk))
                    {
                        return(EncodingsRegistry.Instance.GetEncoding(936).GetString(b));
                    }
                    else if (Encoding.Equals(PdfName.Bigfive))
                    {
                        return(EncodingsRegistry.Instance.GetEncoding(950).GetString(b));
                    }
                }
                catch
                {
                }
                return(vs.ToUnicodeString());
            }
            return(null);
        }
예제 #3
0
        protected virtual void ReadFields()
        {
            catalog = trailer.GetAsDict(PdfName.ROOT);
            PdfDictionary fdf = catalog.GetAsDict(PdfName.FDF);

            if (fdf == null)
            {
                return;
            }
            PdfString fs = fdf.GetAsString(PdfName.F);

            if (fs != null)
            {
                fileSpec = fs.ToUnicodeString();
            }
            PdfArray fld = fdf.GetAsArray(PdfName.FIELDS);

            if (fld == null)
            {
                return;
            }
            encoding = fdf.GetAsName(PdfName.ENCODING);
            PdfDictionary merged = new PdfDictionary();

            merged.Put(PdfName.KIDS, fld);
            KidNode(merged, "");
        }
예제 #4
0
        protected virtual void KidNode(PdfDictionary merged, String name)
        {
            PdfArray kids = merged.GetAsArray(PdfName.KIDS);

            if (kids == null || kids.Size == 0)
            {
                if (name.Length > 0)
                {
                    name = name.Substring(1);
                }
                fields[name] = merged;
            }
            else
            {
                merged.Remove(PdfName.KIDS);
                for (int k = 0; k < kids.Size; ++k)
                {
                    PdfDictionary dic = new PdfDictionary();
                    dic.Merge(merged);
                    PdfDictionary newDic  = kids.GetAsDict(k);
                    PdfString     t       = newDic.GetAsString(PdfName.T);
                    String        newName = name;
                    if (t != null)
                    {
                        newName += "." + t.ToUnicodeString();
                    }
                    dic.Merge(newDic);
                    dic.Remove(PdfName.T);
                    KidNode(dic, newName);
                }
            }
        }
예제 #5
0
        internal static String GetCOName(PdfReader reader, PRIndirectReference refi)
        {
            String name = "";

            while (refi != null)
            {
                PdfObject obj = PdfReader.GetPdfObject(refi);
                if (obj == null || obj.Type != PdfObject.DICTIONARY)
                {
                    break;
                }
                PdfDictionary dic = (PdfDictionary)obj;
                PdfString     t   = dic.GetAsString(PdfName.T);
                if (t != null)
                {
                    name = t.ToUnicodeString() + "." + name;
                }
                refi = (PRIndirectReference)dic.Get(PdfName.PARENT);
            }
            if (name.EndsWith("."))
            {
                name = name.Substring(0, name.Length - 1);
            }
            return(name);
        }
예제 #6
0
        protected virtual void KidNode(PdfDictionary merged, String name)
        {
            PdfArray kids = (PdfArray)GetPdfObject(merged.Get(PdfName.KIDS));

            if (kids == null || kids.ArrayList.Count == 0)
            {
                if (name.Length > 0)
                {
                    name = name.Substring(1);
                }
                fields[name] = merged;
            }
            else
            {
                merged.Remove(PdfName.KIDS);
                ArrayList ar = kids.ArrayList;
                for (int k = 0; k < ar.Count; ++k)
                {
                    PdfDictionary dic = new PdfDictionary();
                    dic.Merge(merged);
                    PdfDictionary newDic  = (PdfDictionary)GetPdfObject((PdfObject)ar[k]);
                    PdfString     t       = (PdfString)GetPdfObject(newDic.Get(PdfName.T));
                    String        newName = name;
                    if (t != null)
                    {
                        newName += "." + t.ToUnicodeString();
                    }
                    dic.Merge(newDic);
                    dic.Remove(PdfName.T);
                    KidNode(dic, newName);
                }
            }
        }
예제 #7
0
        /**
         * Parses the ToUnicode entry, if present, and constructs a CMap for it
         * @since 2.1.7
         */
        private void ProcessToUnicode()
        {
            PdfObject toUni = PdfReader.GetPdfObjectRelease(fontDic.Get(PdfName.TOUNICODE));

            if (toUni is PRStream)
            {
                try {
                    byte[] touni           = PdfReader.GetStreamBytes((PRStream)toUni);
                    CidLocationFromByte lb = new CidLocationFromByte(touni);
                    toUnicodeCmap = new CMapToUnicode();
                    CMapParserEx.ParseCid("", toUnicodeCmap, lb);
                    uni2cid = toUnicodeCmap.CreateReverseMapping();
                } catch {
                    toUnicodeCmap = null;
                    uni2cid       = null;
                    // technically, we should log this or provide some sort of feedback... but sometimes the cmap will be junk, but it's still possible to get text, so we don't want to throw an exception
                    //throw new IllegalStateException("Unable to process ToUnicode map - " + e.GetMessage(), e);
                }
            }
            else if (isType0)
            {
                // fake a ToUnicode for CJK Identity-H fonts
                try {
                    PdfName encodingName = fontDic.GetAsName(PdfName.ENCODING);
                    if (encodingName == null)
                    {
                        return;
                    }
                    String enc = PdfName.DecodeName(encodingName.ToString());
                    if (!enc.Equals("Identity-H"))
                    {
                        return;
                    }
                    PdfArray      df      = (PdfArray)PdfReader.GetPdfObjectRelease(fontDic.Get(PdfName.DESCENDANTFONTS));
                    PdfDictionary cidft   = (PdfDictionary)PdfReader.GetPdfObjectRelease(df[0]);
                    PdfDictionary cidinfo = cidft.GetAsDict(PdfName.CIDSYSTEMINFO);
                    if (cidinfo == null)
                    {
                        return;
                    }
                    PdfString ordering = cidinfo.GetAsString(PdfName.ORDERING);
                    if (ordering == null)
                    {
                        return;
                    }
                    CMapToUnicode touni = IdentityToUnicode.GetMapFromOrdering(ordering.ToUnicodeString());
                    if (touni == null)
                    {
                        return;
                    }
                    toUnicodeCmap = touni;
                    uni2cid       = toUnicodeCmap.CreateReverseMapping();
                } catch (IOException e) {
                    toUnicodeCmap = null;
                    uni2cid       = null;
                }
            }
        }
예제 #8
0
 private String DecodeString(PdfString ps)
 {
     if (ps.IsHexWriting())
     {
         return(PdfEncodings.ConvertToString(ps.GetBytes(), "UnicodeBigUnmarked"));
     }
     else
     {
         return(ps.ToUnicodeString());
     }
 }
예제 #9
0
        protected virtual void ReadFields()
        {
            catalog = (PdfDictionary)GetPdfObject(trailer.Get(PdfName.ROOT));
            PdfDictionary fdf = (PdfDictionary)GetPdfObject(catalog.Get(PdfName.FDF));
            PdfString     fs  = (PdfString)GetPdfObject(fdf.Get(PdfName.F));

            if (fs != null)
            {
                fileSpec = fs.ToUnicodeString();
            }
            PdfArray fld = (PdfArray)GetPdfObject(fdf.Get(PdfName.FIELDS));

            if (fld == null)
            {
                return;
            }
            encoding = (PdfName)GetPdfObject(fdf.Get(PdfName.ENCODING));
            PdfDictionary merged = new PdfDictionary();

            merged.Put(PdfName.KIDS, fld);
            KidNode(merged, "");
        }
예제 #10
0
 private String DecodeString(PdfString ps) {
     if (ps.IsHexWriting())
         return PdfEncodings.ConvertToString(ps.GetBytes(), "UnicodeBigUnmarked");
     else
         return ps.ToUnicodeString();
 }
예제 #11
0
        private static ArrayList BookmarkDepth(PdfReader reader, PdfDictionary outline, IntHashtable pages)
        {
            ArrayList list = new ArrayList();

            while (outline != null)
            {
                Hashtable map   = new Hashtable();
                PdfString title = (PdfString)PdfReader.GetPdfObjectRelease(outline.Get(PdfName.TITLE));
                map["Title"] = title.ToUnicodeString();
                PdfArray color = (PdfArray)PdfReader.GetPdfObjectRelease(outline.Get(PdfName.C));
                if (color != null && color.ArrayList.Count == 3)
                {
                    ByteBuffer outp = new ByteBuffer();
                    ArrayList  arr  = color.ArrayList;
                    outp.Append(((PdfNumber)arr[0]).FloatValue).Append(' ');
                    outp.Append(((PdfNumber)arr[1]).FloatValue).Append(' ');
                    outp.Append(((PdfNumber)arr[2]).FloatValue);
                    map["Color"] = PdfEncodings.ConvertToString(outp.ToByteArray(), null);
                }
                PdfNumber style = (PdfNumber)PdfReader.GetPdfObjectRelease(outline.Get(PdfName.F));
                if (style != null)
                {
                    int    f = style.IntValue;
                    String s = "";
                    if ((f & 1) != 0)
                    {
                        s += "italic ";
                    }
                    if ((f & 2) != 0)
                    {
                        s += "bold ";
                    }
                    s = s.Trim();
                    if (s.Length != 0)
                    {
                        map["Style"] = s;
                    }
                }
                PdfNumber count = (PdfNumber)PdfReader.GetPdfObjectRelease(outline.Get(PdfName.COUNT));
                if (count != null && count.IntValue < 0)
                {
                    map["Open"] = "false";
                }
                try {
                    PdfObject dest = PdfReader.GetPdfObjectRelease(outline.Get(PdfName.DEST));
                    if (dest != null)
                    {
                        MapGotoBookmark(map, dest, pages); //changed by ujihara 2004-06-13
                    }
                    else
                    {
                        PdfDictionary action = (PdfDictionary)PdfReader.GetPdfObjectRelease(outline.Get(PdfName.A));
                        if (action != null)
                        {
                            if (PdfName.GOTO.Equals(PdfReader.GetPdfObjectRelease(action.Get(PdfName.S))))
                            {
                                dest = PdfReader.GetPdfObjectRelease(action.Get(PdfName.D));
                                if (dest != null)
                                {
                                    MapGotoBookmark(map, dest, pages);
                                }
                            }
                            else if (PdfName.URI.Equals(PdfReader.GetPdfObjectRelease(action.Get(PdfName.S))))
                            {
                                map["Action"] = "URI";
                                map["URI"]    = ((PdfString)PdfReader.GetPdfObjectRelease(action.Get(PdfName.URI))).ToUnicodeString();
                            }
                            else if (PdfName.GOTOR.Equals(PdfReader.GetPdfObjectRelease(action.Get(PdfName.S))))
                            {
                                dest = PdfReader.GetPdfObjectRelease(action.Get(PdfName.D));
                                if (dest != null)
                                {
                                    if (dest.IsString())
                                    {
                                        map["Named"] = dest.ToString();
                                    }
                                    else if (dest.IsName())
                                    {
                                        map["NamedN"] = PdfName.DecodeName(dest.ToString());
                                    }
                                    else if (dest.IsArray())
                                    {
                                        ArrayList     arr = ((PdfArray)dest).ArrayList;
                                        StringBuilder s   = new StringBuilder();
                                        s.Append(arr[0].ToString());
                                        s.Append(' ').Append(arr[1].ToString());
                                        for (int k = 2; k < arr.Count; ++k)
                                        {
                                            s.Append(' ').Append(arr[k].ToString());
                                        }
                                        map["Page"] = s.ToString();
                                    }
                                }
                                map["Action"] = "GoToR";
                                PdfObject file = PdfReader.GetPdfObjectRelease(action.Get(PdfName.F));
                                if (file != null)
                                {
                                    if (file.IsString())
                                    {
                                        map["File"] = ((PdfString)file).ToUnicodeString();
                                    }
                                    else if (file.IsDictionary())
                                    {
                                        file = PdfReader.GetPdfObject(((PdfDictionary)file).Get(PdfName.F));
                                        if (file.IsString())
                                        {
                                            map["File"] = ((PdfString)file).ToUnicodeString();
                                        }
                                    }
                                }
                                PdfObject newWindow = PdfReader.GetPdfObjectRelease(action.Get(PdfName.NEWWINDOW));
                                if (newWindow != null)
                                {
                                    map["NewWindow"] = newWindow.ToString();
                                }
                            }
                            else if (PdfName.LAUNCH.Equals(PdfReader.GetPdfObjectRelease(action.Get(PdfName.S))))
                            {
                                map["Action"] = "Launch";
                                PdfObject file = PdfReader.GetPdfObjectRelease(action.Get(PdfName.F));
                                if (file == null)
                                {
                                    file = PdfReader.GetPdfObjectRelease(action.Get(PdfName.WIN));
                                }
                                if (file != null)
                                {
                                    if (file.IsString())
                                    {
                                        map["File"] = ((PdfString)file).ToUnicodeString();
                                    }
                                    else if (file.IsDictionary())
                                    {
                                        file = PdfReader.GetPdfObjectRelease(((PdfDictionary)file).Get(PdfName.F));
                                        if (file.IsString())
                                        {
                                            map["File"] = ((PdfString)file).ToUnicodeString();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch  {
                    //empty on purpose
                }
                PdfDictionary first = (PdfDictionary)PdfReader.GetPdfObjectRelease(outline.Get(PdfName.FIRST));
                if (first != null)
                {
                    map["Kids"] = BookmarkDepth(reader, first, pages);
                }
                list.Add(map);
                outline = (PdfDictionary)PdfReader.GetPdfObjectRelease(outline.Get(PdfName.NEXT));
            }
            return(list);
        }
예제 #12
0
        private void DrawOverlayText(PdfContentByte canvas, IList<Rectangle> textRectangles, PdfString overlayText, 
                                     PdfString otDA, PdfNumber otQ, PdfBoolean otRepeat) {
            ColumnText ct = new ColumnText(canvas);
            ct.SetLeading(0, 1.2F);
            ct.UseAscender = true;

            String otStr = overlayText.ToUnicodeString();

            canvas.SaveState();
            IDictionary<string, IList<object>> parsedDA = ParseDAParam(otDA);

            Font font = null;

            if (parsedDA.ContainsKey(STROKE_COLOR)) {
                IList<object> strokeColorArgs = parsedDA[STROKE_COLOR];
                SetStrokeColor(canvas, strokeColorArgs);
            }

            if (parsedDA.ContainsKey(FILL_COLOR)) {
                IList<object> fillColorArgs = parsedDA[FILL_COLOR];
                SetFillColor(canvas, fillColorArgs);
            }

            if (parsedDA.ContainsKey("Tf")) {
                IList<object> tfArgs = parsedDA["Tf"];
                font = RetrieveFontFromAcroForm((PdfName) tfArgs[0], (PdfNumber) tfArgs[1]);
            }

            foreach (Rectangle textRect in textRectangles) {
                ct.SetSimpleColumn(textRect);

                if (otQ != null) {
                    ct.Alignment = otQ.IntValue;
                }

                Phrase otPhrase;

                if (font != null) {
                    otPhrase = new Phrase(otStr, font);
                } else {
                    otPhrase = new Phrase(otStr);
                }

                float y = ct.YLine;

                if (otRepeat != null && otRepeat.BooleanValue) {
                    int status = ct.Go(true);

                    while (!ColumnText.HasMoreText(status)) {
                        otPhrase.Add(otStr);
                        ct.SetText(otPhrase);
                        ct.YLine = y;
                        status = ct.Go(true);
                    }
                }

                ct.SetText(otPhrase);
                ct.YLine = y;
                ct.Go();
            }

            canvas.RestoreState();
        }
예제 #13
0
파일: FdfReader.cs 프로젝트: NKINC/pdforms
        virtual public String[] GetFieldValues(String name)
        {
            PdfDictionary field = GetField(name);

            if (field == null)
            {
                return new String[] { }
            }
            ;
            PdfObject v = GetPdfObject(field.Get(PdfName.V));

            if (v == null)
            {
                return new String[] { }
            }
            ;
            if (v.IsName())
            {
                return new String[] { PdfName.DecodeName(((PdfName)v).ToString()) }
            }
            ;
            else if (v.IsString())
            {
                PdfString vs = (PdfString)v;

                if (encoding == null || vs.Encoding != null)
                {
                    return new String[] { vs.ToUnicodeString() }
                }
                ;
                byte[] b = vs.GetBytes();
                if (b.Length >= 2 && b[0] == (byte)254 && b[1] == (byte)255)
                {
                    return new String[] { vs.ToUnicodeString() }
                }
                ;
                try
                {
                    if (encoding.Equals(PdfName.SHIFT_JIS))
                    {
                        return new String[] { Encoding.GetEncoding(932).GetString(b) }
                    }
                    ;
                    else if (encoding.Equals(PdfName.UHC))
                    {
                        return new String[] { Encoding.GetEncoding(949).GetString(b) }
                    }
                    ;
                    else if (encoding.Equals(PdfName.GBK))
                    {
                        return new String[] { Encoding.GetEncoding(936).GetString(b) }
                    }
                    ;
                    else if (encoding.Equals(PdfName.BIGFIVE))
                    {
                        return new String[] { Encoding.GetEncoding(950).GetString(b) }
                    }
                    ;
                    else if (encoding.Equals(PdfName.UTF_8))
                    {
                        return new String[] { Encoding.UTF8.GetString(b) }
                    }
                    ;
                }
                catch
                {
                }
                return(new String[] { vs.ToUnicodeString() });
            }
            else if (v.IsArray())
            {
                PdfArray vsArray = (PdfArray)v;
                System.Collections.Generic.List <String> vals = new System.Collections.Generic.List <String>();
                for (Int32 vsIdx = 0; vsIdx < vsArray.Size; vsIdx++)
                {
                    if (vsArray[vsIdx] == null)
                    {
                        vals.Add("");
                    }
                    else if (vsArray[vsIdx].IsString())
                    {
                        PdfString vs = (PdfString)vsArray[vsIdx];
                        if (encoding == null || vs.Encoding != null)
                        {
                            vals.Add(vs.ToUnicodeString());
                        }
                        else
                        {
                            byte[] b1 = vs.GetBytes();
                            if (b1.Length >= 2 && b1[0] == (byte)254 && b1[1] == (byte)255)
                            {
                                vals.Add(vs.ToUnicodeString());
                            }
                            else
                            {
                                try
                                {
                                    if (encoding.Equals(PdfName.SHIFT_JIS))
                                    {
                                        vals.Add(Encoding.GetEncoding(932).GetString(b1));
                                    }
                                    else if (encoding.Equals(PdfName.UHC))
                                    {
                                        vals.Add(Encoding.GetEncoding(949).GetString(b1));
                                    }
                                    else if (encoding.Equals(PdfName.GBK))
                                    {
                                        vals.Add(Encoding.GetEncoding(936).GetString(b1));
                                    }
                                    else if (encoding.Equals(PdfName.BIGFIVE))
                                    {
                                        vals.Add(Encoding.GetEncoding(950).GetString(b1));
                                    }
                                    else if (encoding.Equals(PdfName.UTF_8))
                                    {
                                        vals.Add(Encoding.UTF8.GetString(b1));
                                    }
                                }
                                catch
                                {
                                }
                            }
                        }
                    }
                    else if (vsArray[vsIdx].IsName())
                    {
                        vals.Add(PdfName.DecodeName(((PdfName)vsArray[vsIdx]).ToString()));
                    }
                }
                return(vals.ToArray());
            }
            return(new String[] { });
        }