ToString() public méthode

public ToString ( ) : string
Résultat string
Exemple #1
0
            private void SerObject(PdfObject obj, int level, ByteBuffer bb, HashSet2 <PdfObject> serialized)
            {
                if (level <= 0)
                {
                    return;
                }
                if (obj == null)
                {
                    bb.Append("$Lnull");
                    return;
                }

                if (obj.IsIndirect())
                {
                    if (serialized.Contains(obj))
                    {
                        return;
                    }
                    else
                    {
                        serialized.Add(obj);
                    }
                }
                obj = PdfReader.GetPdfObject(obj);
                if (obj.IsStream())
                {
                    bb.Append("$B");
                    SerDic((PdfDictionary)obj, level - 1, bb, serialized);
                    if (level > 0)
                    {
                        bb.Append(DigestAlgorithms.Digest("MD5", PdfReader.GetStreamBytesRaw((PRStream)obj)));
                    }
                }
                else if (obj.IsDictionary())
                {
                    SerDic((PdfDictionary)obj, level - 1, bb, serialized);
                }
                else if (obj.IsArray())
                {
                    SerArray((PdfArray)obj, level - 1, bb, serialized);
                }
                else if (obj.IsString())
                {
                    bb.Append("$S").Append(obj.ToString());
                }
                else if (obj.IsName())
                {
                    bb.Append("$N").Append(obj.ToString());
                }
                else
                {
                    bb.Append("$L").Append(obj.ToString());
                }
            }
Exemple #2
0
 private static void MapGotoBookmark(Hashtable map, PdfObject dest, IntHashtable pages)
 {
     if (dest.IsString())
     {
         map["Named"] = dest.ToString();
     }
     else if (dest.IsName())
     {
         map["Named"] = PdfName.DecodeName(dest.ToString());
     }
     else if (dest.IsArray())
     {
         map["Page"] = MakeBookmarkParam((PdfArray)dest, pages); //changed by ujihara 2004-06-13
     }
     map["Action"] = "GoTo";
 }
Exemple #3
0
            private void serObject(PdfObject obj, int level, ByteBuffer bb)
            {
                if (level <= 0)
                {
                    return;
                }

                if (obj == null)
                {
                    bb.Append("$Lnull");
                    return;
                }
                obj = PdfReader.GetPdfObject(obj);
                if (obj.IsStream())
                {
                    bb.Append("$B");
                    serDic((PdfDictionary)obj, level - 1, bb);
                    if (level > 0)
                    {
                        using (var md5 = MD5.Create())
                        {
                            bb.Append(md5.ComputeHash(PdfReader.GetStreamBytesRaw((PrStream)obj)));
                        }
                    }
                }
                else if (obj.IsDictionary())
                {
                    serDic((PdfDictionary)obj, level - 1, bb);
                }
                else if (obj.IsArray())
                {
                    serArray((PdfArray)obj, level - 1, bb);
                }
                else if (obj.IsString())
                {
                    bb.Append("$S").Append(obj.ToString());
                }
                else if (obj.IsName())
                {
                    bb.Append("$N").Append(obj.ToString());
                }
                else
                {
                    bb.Append("$L").Append(obj.ToString());
                }
            }
 private void SerObject(PdfObject obj, int level, ByteBuffer bb)
 {
     if (level <= 0)
     {
         return;
     }
     if (obj == null)
     {
         bb.Append("$Lnull");
         return;
     }
     obj = PdfReader.GetPdfObject(obj);
     if (obj.IsStream())
     {
         bb.Append("$B");
         SerDic((PdfDictionary)obj, level - 1, bb);
         if (level > 0)
         {
             bb.Append(PdfEncryption.DigestComputeHash("MD5", PdfReader.GetStreamBytesRaw((PRStream)obj)));
         }
     }
     else if (obj.IsDictionary())
     {
         SerDic((PdfDictionary)obj, level - 1, bb);
     }
     else if (obj.IsArray())
     {
         SerArray((PdfArray)obj, level - 1, bb);
     }
     else if (obj.IsString())
     {
         bb.Append("$S").Append(obj.ToString());
     }
     else if (obj.IsName())
     {
         bb.Append("$N").Append(obj.ToString());
     }
     else
     {
         bb.Append("$L").Append(obj.ToString());
     }
 }
Exemple #5
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static List <System.Drawing.Image> ExtractImages(string PDFSourcePath)
        {
            List <System.Drawing.Image> imgList = new List <System.Drawing.Image>();

            RandomAccessFileOrArray RAFObj = null;
            PdfReader PDFReaderObj         = null;
            PdfObject PDFObj      = null;
            PdfStream PDFStremObj = null;

            try
            {
                RAFObj       = new RandomAccessFileOrArray(PDFSourcePath);
                PDFReaderObj = new PdfReader(RAFObj, null);
                for (int i = 0; i <= PDFReaderObj.XrefSize - 1; i++)
                {
                    PDFObj = PDFReaderObj.GetPdfObject(i);

                    if ((PDFObj != null) && PDFObj.IsStream())
                    {
                        PDFStremObj = (PdfStream)PDFObj;
                        iTextSharp.text.pdf.PdfObject subtype = PDFStremObj.Get(PdfName.SUBTYPE);

                        if ((subtype != null) && subtype.ToString() == PdfName.IMAGE.ToString())
                        {
                            try
                            {
                                PdfImageObject PdfImageObj = new PdfImageObject((PRStream)PDFStremObj);

                                System.Drawing.Image ImgPDF = PdfImageObj.GetDrawingImage();


                                imgList.Add(ImgPDF);
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                }
                PDFReaderObj.Close();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(imgList);
        }
Exemple #6
0
        private static List <System.Drawing.Image> ExtractImages(byte[] PDFSourcePath)
        {
            List <System.Drawing.Image> ImgList = new List <System.Drawing.Image>();

            iTextSharp.text.pdf.PdfReader PDFReaderObj = null;
            iTextSharp.text.pdf.PdfObject PDFObj       = null;
            iTextSharp.text.pdf.PdfStream PDFStremObj  = null;

            try
            {
                PDFReaderObj = new iTextSharp.text.pdf.PdfReader(PDFSourcePath, null);

                for (int i = 0; i <= PDFReaderObj.XrefSize - 1; i++)
                {
                    PDFObj = PDFReaderObj.GetPdfObject(i);

                    if ((PDFObj != null) && PDFObj.IsStream())
                    {
                        PDFStremObj = (iTextSharp.text.pdf.PdfStream)PDFObj;
                        iTextSharp.text.pdf.PdfObject subtype = PDFStremObj.Get(iTextSharp.text.pdf.PdfName.SUBTYPE);

                        if ((subtype != null) && subtype.ToString() == iTextSharp.text.pdf.PdfName.IMAGE.ToString())
                        {
                            try
                            {
                                iTextSharp.text.pdf.parser.PdfImageObject PdfImageObj =
                                    new iTextSharp.text.pdf.parser.PdfImageObject((iTextSharp.text.pdf.PRStream)PDFStremObj);

                                System.Drawing.Image ImgPDF = PdfImageObj.GetDrawingImage();


                                ImgList.Add(ImgPDF);
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                }
                PDFReaderObj.Close();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(ImgList);
        }
Exemple #7
0
        private void FillMetrics(byte[] touni, IntHashtable widths, int dw)
        {
            PdfContentParser ps       = new PdfContentParser(new PRTokeniser(new RandomAccessFileOrArray(new RandomAccessSourceFactory().CreateSource(touni))));
            PdfObject        ob       = null;
            bool             notFound = true;
            int nestLevel             = 0;
            int maxExc = 50;

            while ((notFound || nestLevel > 0))
            {
                try {
                    ob = ps.ReadPRObject();
                }
                catch {
                    if (--maxExc < 0)
                    {
                        break;
                    }
                    continue;
                }
                if (ob == null)
                {
                    break;
                }
                if (ob.Type == PdfContentParser.COMMAND_TYPE)
                {
                    if (ob.ToString().Equals("begin"))
                    {
                        notFound = false;
                        nestLevel++;
                    }
                    else if (ob.ToString().Equals("end"))
                    {
                        nestLevel--;
                    }
                    else if (ob.ToString().Equals("beginbfchar"))
                    {
                        while (true)
                        {
                            PdfObject nx = ps.ReadPRObject();
                            if (nx.ToString().Equals("endbfchar"))
                            {
                                break;
                            }
                            String cid = DecodeString((PdfString)nx);
                            String uni = DecodeString((PdfString)ps.ReadPRObject());
                            if (uni.Length == 1)
                            {
                                int cidc = (int)cid[0];
                                int unic = (int)uni[uni.Length - 1];
                                int w    = dw;
                                if (widths.ContainsKey(cidc))
                                {
                                    w = widths[cidc];
                                }
                                metrics[unic] = new int[] { cidc, w };
                            }
                        }
                    }
                    else if (ob.ToString().Equals("beginbfrange"))
                    {
                        while (true)
                        {
                            PdfObject nx = ps.ReadPRObject();
                            if (nx.ToString().Equals("endbfrange"))
                            {
                                break;
                            }
                            String    cid1  = DecodeString((PdfString)nx);
                            String    cid2  = DecodeString((PdfString)ps.ReadPRObject());
                            int       cid1c = (int)cid1[0];
                            int       cid2c = (int)cid2[0];
                            PdfObject ob2   = ps.ReadPRObject();
                            if (ob2.IsString())
                            {
                                String uni = DecodeString((PdfString)ob2);
                                if (uni.Length == 1)
                                {
                                    int unic = (int)uni[uni.Length - 1];
                                    for (; cid1c <= cid2c; cid1c++, unic++)
                                    {
                                        int w = dw;
                                        if (widths.ContainsKey(cid1c))
                                        {
                                            w = widths[cid1c];
                                        }
                                        metrics[unic] = new int[] { cid1c, w };
                                    }
                                }
                            }
                            else
                            {
                                PdfArray a = (PdfArray)ob2;
                                for (int j = 0; j < a.Size; ++j, ++cid1c)
                                {
                                    String uni = DecodeString(a.GetAsString(j));
                                    if (uni.Length == 1)
                                    {
                                        int unic = (int)uni[uni.Length - 1];
                                        int w    = dw;
                                        if (widths.ContainsKey(cid1c))
                                        {
                                            w = widths[cid1c];
                                        }
                                        metrics[unic] = new int[] { cid1c, w };
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #8
0
        public static bool CompareObjects(PdfObject value1, PdfObject value2) {
            value2 = GetDirectObject(value2);
            if (value2 == null)
                return false;
            if (value1.Type != value2.Type)
                return false;

            if (value1.IsBoolean()){
                if (value1 == value2)
                    return true;
                if (value2 is PdfBoolean) {
                    return ((PdfBoolean)value1).BooleanValue == ((PdfBoolean)value2).BooleanValue;
                }
                return false;
            } else if (value1.IsName()) {
                return value1.Equals(value2);
            } else if (value1.IsNumber()){
                if (value1 == value2)
                    return true;
                if (value2 is PdfNumber) {
                    return ((PdfNumber)value1).DoubleValue == ((PdfNumber)value2).DoubleValue;
                }
                return false;
            } else if (value1.IsNull()){
                if (value1 == value2)
                    return true;
                if (value2 is PdfNull)
                    return true;
                return false;
            } else if (value1.IsString()){
                if (value1 == value2)
                    return true;
                if (value2 is PdfString) {
                    return ((value2 == null && value1.ToString() == null)
                        || value1.ToString() == value2.ToString());
                }
                return false;
            }
            if (value1.IsArray()) {
                PdfArray array1 = (PdfArray)value1;
                PdfArray array2 = (PdfArray)value2;
                if (array1.Size != array2.Size)
                    return false;
                for (int i = 0; i < array1.Size; ++i)
                    if (!CompareObjects(array1[i],array2[i]))
                        return false;
                return true;
            }
            if (value1.IsDictionary()) {
                PdfDictionary first = (PdfDictionary)value1;
                PdfDictionary second = (PdfDictionary)value2;
                if (first.Size != second.Size)
                    return false;
                foreach (PdfName name in first.hashMap.Keys) {
                    if (!CompareObjects(first.Get(name),second.Get(name)))
                        return false;
                }
                return true;
            }
            return false;
        }
Exemple #9
0
        public static bool CompareObjects(PdfObject value1, PdfObject value2)
        {
            value2 = GetDirectObject(value2);
            if (value2 == null)
            {
                return(false);
            }
            if (value1.Type != value2.Type)
            {
                return(false);
            }

            if (value1.IsBoolean())
            {
                if (value1 == value2)
                {
                    return(true);
                }
                if (value2 is PdfBoolean)
                {
                    return(((PdfBoolean)value1).BooleanValue == ((PdfBoolean)value2).BooleanValue);
                }
                return(false);
            }
            else if (value1.IsName())
            {
                return(value1.Equals(value2));
            }
            else if (value1.IsNumber())
            {
                if (value1 == value2)
                {
                    return(true);
                }
                if (value2 is PdfNumber)
                {
                    return(((PdfNumber)value1).DoubleValue == ((PdfNumber)value2).DoubleValue);
                }
                return(false);
            }
            else if (value1.IsNull())
            {
                if (value1 == value2)
                {
                    return(true);
                }
                if (value2 is PdfNull)
                {
                    return(true);
                }
                return(false);
            }
            else if (value1.IsString())
            {
                if (value1 == value2)
                {
                    return(true);
                }
                if (value2 is PdfString)
                {
                    return((value2 == null && value1.ToString() == null) ||
                           value1.ToString() == value2.ToString());
                }
                return(false);
            }
            if (value1.IsArray())
            {
                PdfArray array1 = (PdfArray)value1;
                PdfArray array2 = (PdfArray)value2;
                if (array1.Size != array2.Size)
                {
                    return(false);
                }
                for (int i = 0; i < array1.Size; ++i)
                {
                    if (!CompareObjects(array1[i], array2[i]))
                    {
                        return(false);
                    }
                }
                return(true);
            }
            if (value1.IsDictionary())
            {
                PdfDictionary first  = (PdfDictionary)value1;
                PdfDictionary second = (PdfDictionary)value2;
                if (first.Size != second.Size)
                {
                    return(false);
                }
                foreach (PdfName name in first.hashMap.Keys)
                {
                    if (!CompareObjects(first.Get(name), second.Get(name)))
                    {
                        return(false);
                    }
                }
                return(true);
            }
            return(false);
        }
        public virtual void WriteAttributes(IAccessibleElement element)
        {
            // I do remember that these lines were necessary to avoid creation of files which are not valid from Acrobat 10 preflight perspective.
            // Now it seems that in Acrobat 11 there's no such problem (I think Acrobat 10 behavior can be considered as a bug) and we can remove those lines.
            // if(top.Writer.GetPdfVersion().Version < PdfWriter.VERSION_1_7)
            //    return;

            if (element is ListItem)
            {
                WriteAttributes((ListItem)element);
            }
            else if (element is Paragraph)
            {
                WriteAttributes((Paragraph)element);
            }
            else if (element is Chunk)
            {
                WriteAttributes((Chunk)element);
            }
            else if (element is Image)
            {
                WriteAttributes((Image)element);
            }
            else if (element is List)
            {
                WriteAttributes((List)element);
            }
            else if (element is ListLabel)
            {
                WriteAttributes((ListLabel)element);
            }
            else if (element is ListBody)
            {
                WriteAttributes((ListBody)element);
            }
            else if (element is PdfPTable)
            {
                WriteAttributes((PdfPTable)element);
            }
            else if (element is PdfPRow)
            {
                WriteAttributes((PdfPRow)element);
            }
            else if (element is PdfPHeaderCell)
            {
                WriteAttributes((PdfPHeaderCell)element);
            }
            else if (element is PdfPCell)
            {
                WriteAttributes((PdfPCell)element);
            }
            else if (element is PdfPTableHeader)
            {
                WriteAttributes((PdfPTableHeader)element);
            }
            else if (element is PdfPTableFooter)
            {
                WriteAttributes((PdfPTableFooter)element);
            }
            else if (element is PdfPTableBody)
            {
                WriteAttributes((PdfPTableBody)element);
            }
            else if (element is PdfDiv)
            {
                WriteAttributes((PdfDiv)element);
            }
            else if (element is PdfTemplate)
            {
                WriteAttributes((PdfTemplate)element);
            }
            else if (element is Document)
            {
                WriteAttributes((Document)element);
            }

            if (element.GetAccessibleAttributes() != null)
            {
                foreach (PdfName key in element.GetAccessibleAttributes().Keys)
                {
                    if (key.Equals(PdfName.ID))
                    {
                        PdfObject attr = element.GetAccessibleAttribute(key);
                        Put(key, attr);
                        top.PutIDTree(attr.ToString(), Reference);
                    }
                    else if (key.Equals(PdfName.LANG) || key.Equals(PdfName.ALT) || key.Equals(PdfName.ACTUALTEXT) || key.Equals(PdfName.E) || key.Equals(PdfName.T))
                    {
                        Put(key, element.GetAccessibleAttribute(key));
                    }
                    else
                    {
                        SetAttribute(key, element.GetAccessibleAttribute(key));
                    }
                }
            }
        }
Exemple #11
0
 private void SerObject(PdfObject obj, int level, ByteBuffer bb)
 {
     if (level <= 0)
         return;
     if (obj == null) {
         bb.Append("$Lnull");
         return;
     }
     obj = PdfReader.GetPdfObject(obj);
     if (obj.IsStream()) {
         bb.Append("$B");
         SerDic((PdfDictionary)obj, level - 1, bb);
         if (level > 0) {
             bb.Append(PdfEncryption.DigestComputeHash("MD5", PdfReader.GetStreamBytesRaw((PRStream)obj)));
         }
     }
     else if (obj.IsDictionary()) {
         SerDic((PdfDictionary)obj, level - 1, bb);
     }
     else if (obj.IsArray()) {
         SerArray((PdfArray)obj, level - 1, bb);
     }
     else if (obj.IsString()) {
         bb.Append("$S").Append(obj.ToString());
     }
     else if (obj.IsName()) {
         bb.Append("$N").Append(obj.ToString());
     }
     else
         bb.Append("$L").Append(obj.ToString());
 }
Exemple #12
0
            private void SerObject(PdfObject obj, int level, ByteBuffer bb, Dictionary <RefKey, int> serialized)
            {
                if (level <= 0)
                {
                    return;
                }
                if (obj == null)
                {
                    bb.Append("$Lnull");
                    return;
                }

                PdfIndirectReference refe    = null;
                ByteBuffer           savedBb = null;

                if (obj.IsIndirect())
                {
                    refe = (PdfIndirectReference)obj;
                    RefKey key = new RefKey(refe);
                    if (serialized.ContainsKey(key))
                    {
                        bb.Append(serialized[key]);
                        return;
                    }
                    else
                    {
                        savedBb = bb;
                        bb      = new ByteBuffer();
                    }
                }
                obj = PdfReader.GetPdfObject(obj);
                if (obj.IsStream())
                {
                    bb.Append("$B");
                    SerDic((PdfDictionary)obj, level - 1, bb, serialized);
                    if (level > 0)
                    {
                        bb.Append(DigestAlgorithms.Digest("MD5", PdfReader.GetStreamBytesRaw((PRStream)obj)));
                    }
                }
                else if (obj.IsDictionary())
                {
                    SerDic((PdfDictionary)obj, level - 1, bb, serialized);
                }
                else if (obj.IsArray())
                {
                    SerArray((PdfArray)obj, level - 1, bb, serialized);
                }
                else if (obj.IsString())
                {
                    bb.Append("$S").Append(obj.ToString());
                }
                else if (obj.IsName())
                {
                    bb.Append("$N").Append(obj.ToString());
                }
                else
                {
                    bb.Append("$L").Append(obj.ToString());
                }

                if (savedBb != null)
                {
                    RefKey key = new RefKey(refe);
                    if (!serialized.ContainsKey(key))
                    {
                        serialized[key] = CalculateHash(bb.Buffer);
                    }
                    savedBb.Append(bb);
                }
            }
Exemple #13
0
        private void FillMetrics(byte[] touni, IntHashtable widths, int dw)
        {
            PdfContentParser ps   = new PdfContentParser(new PRTokeniser(touni));
            PdfObject        ob   = null;
            PdfObject        last = null;

            while ((ob = ps.ReadPRObject()) != null)
            {
                if (ob.Type == PdfContentParser.COMMAND_TYPE)
                {
                    if (ob.ToString().Equals("beginbfchar"))
                    {
                        int n = ((PdfNumber)last).IntValue;
                        for (int k = 0; k < n; ++k)
                        {
                            String cid = DecodeString((PdfString)ps.ReadPRObject());
                            String uni = DecodeString((PdfString)ps.ReadPRObject());
                            if (uni.Length == 1)
                            {
                                int cidc = (int)cid[0];
                                int unic = (int)uni[uni.Length - 1];
                                int w    = dw;
                                if (widths.ContainsKey(cidc))
                                {
                                    w = widths[cidc];
                                }
                                metrics[unic] = new int[] { cidc, w };
                            }
                        }
                    }
                    else if (ob.ToString().Equals("beginbfrange"))
                    {
                        int n = ((PdfNumber)last).IntValue;
                        for (int k = 0; k < n; ++k)
                        {
                            String    cid1  = DecodeString((PdfString)ps.ReadPRObject());
                            String    cid2  = DecodeString((PdfString)ps.ReadPRObject());
                            int       cid1c = (int)cid1[0];
                            int       cid2c = (int)cid2[0];
                            PdfObject ob2   = ps.ReadPRObject();
                            if (ob2.IsString())
                            {
                                String uni = DecodeString((PdfString)ob2);
                                if (uni.Length == 1)
                                {
                                    int unic = (int)uni[uni.Length - 1];
                                    for (; cid1c <= cid2c; cid1c++, unic++)
                                    {
                                        int w = dw;
                                        if (widths.ContainsKey(cid1c))
                                        {
                                            w = widths[cid1c];
                                        }
                                        metrics[unic] = new int[] { cid1c, w };
                                    }
                                }
                            }
                            else
                            {
                                ArrayList ar = ((PdfArray)ob2).ArrayList;
                                for (int j = 0; j < ar.Count; ++j, ++cid1c)
                                {
                                    String uni = DecodeString((PdfString)ar[j]);
                                    if (uni.Length == 1)
                                    {
                                        int unic = (int)uni[uni.Length - 1];
                                        int w    = dw;
                                        if (widths.ContainsKey(cid1c))
                                        {
                                            w = widths[cid1c];
                                        }
                                        metrics[unic] = new int[] { cid1c, w };
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    last = ob;
                }
            }
        }
Exemple #14
0
 public override string ToString()
 {
     return(new StringBuilder().Append(number).Append(' ').Append(generation).Append(" R: ").Append(objecti != null ? objecti.ToString(): "null").ToString());
 }
Exemple #15
0
        private void FillMetrics(byte[] touni, IntHashtable widths, int dw)
        {
            PdfContentParser ps       = new PdfContentParser(new PRTokeniser(touni));
            PdfObject        ob       = null;
            PdfObject        last     = null;
            bool             notFound = true;
            int nestLevel             = 0;

            while ((notFound || nestLevel > 0) && (ob = ps.ReadPRObject()) != null)
            {
                if (ob.Type == PdfContentParser.COMMAND_TYPE)
                {
                    if (ob.ToString().Equals("begin"))
                    {
                        notFound = false;
                        nestLevel++;
                    }
                    else if (ob.ToString().Equals("end"))
                    {
                        nestLevel--;
                    }
                    else if (ob.ToString().Equals("beginbfchar"))
                    {
                        int n = ((PdfNumber)last).IntValue;
                        for (int k = 0; k < n; ++k)
                        {
                            String cid = DecodeString((PdfString)ps.ReadPRObject());
                            String uni = DecodeString((PdfString)ps.ReadPRObject());
                            if (uni.Length == 1)
                            {
                                int cidc = (int)cid[0];
                                int unic = (int)uni[uni.Length - 1];
                                int w    = dw;
                                if (widths.ContainsKey(cidc))
                                {
                                    w = widths[cidc];
                                }
                                metrics[unic] = new int[] { cidc, w };
                            }
                        }
                    }
                    else if (ob.ToString().Equals("beginbfrange"))
                    {
                        int n = ((PdfNumber)last).IntValue;
                        for (int k = 0; k < n; ++k)
                        {
                            String    cid1  = DecodeString((PdfString)ps.ReadPRObject());
                            String    cid2  = DecodeString((PdfString)ps.ReadPRObject());
                            int       cid1c = (int)cid1[0];
                            int       cid2c = (int)cid2[0];
                            PdfObject ob2   = ps.ReadPRObject();
                            if (ob2.IsString())
                            {
                                String uni = DecodeString((PdfString)ob2);
                                if (uni.Length == 1)
                                {
                                    int unic = (int)uni[uni.Length - 1];
                                    for (; cid1c <= cid2c; cid1c++, unic++)
                                    {
                                        int w = dw;
                                        if (widths.ContainsKey(cid1c))
                                        {
                                            w = widths[cid1c];
                                        }
                                        metrics[unic] = new int[] { cid1c, w };
                                    }
                                }
                            }
                            else
                            {
                                PdfArray a = (PdfArray)ob2;
                                for (int j = 0; j < a.Size; ++j, ++cid1c)
                                {
                                    String uni = DecodeString(a.GetAsString(j));
                                    if (uni.Length == 1)
                                    {
                                        int unic = (int)uni[uni.Length - 1];
                                        int w    = dw;
                                        if (widths.ContainsKey(cid1c))
                                        {
                                            w = widths[cid1c];
                                        }
                                        metrics[unic] = new int[] { cid1c, w };
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    last = ob;
                }
            }
        }
Exemple #16
0
            private void SerObject(PdfObject obj, int level, ByteBuffer bb, Dictionary<RefKey, int> serialized)
            {
                if (level <= 0)
                    return;
                if (obj == null) {
                    bb.Append("$Lnull");
                    return;
                }

                PdfIndirectReference refe = null;
                ByteBuffer savedBb = null;

                if (obj.IsIndirect()) {
                    refe = (PdfIndirectReference)obj;
                    RefKey key = new RefKey(refe);
                    if (serialized.ContainsKey(key)) {
                        bb.Append(serialized[key]);
                        return;
                    }
                    else {
                        savedBb = bb;
                        bb = new ByteBuffer();
                    }
                }
                obj = PdfReader.GetPdfObject(obj);
                if (obj.IsStream()) {
                    bb.Append("$B");
                    SerDic((PdfDictionary)obj, level - 1, bb, serialized);
                    if (level > 0) {
                        bb.Append(DigestAlgorithms.Digest("MD5", PdfReader.GetStreamBytesRaw((PRStream)obj)));
                    }
                }
                else if (obj.IsDictionary()) {
                    SerDic((PdfDictionary)obj, level - 1, bb,serialized);
                }
                else if (obj.IsArray()) {
                    SerArray((PdfArray)obj, level - 1, bb,serialized);
                }
                else if (obj.IsString()) {
                    bb.Append("$S").Append(obj.ToString());
                }
                else if (obj.IsName()) {
                    bb.Append("$N").Append(obj.ToString());
                }
                else
                    bb.Append("$L").Append(obj.ToString());

                if (savedBb != null) {
                    RefKey key = new RefKey(refe);
                    if (!serialized.ContainsKey(key))
                        serialized[key] = CalculateHash(bb.Buffer);
                    savedBb.Append(bb);
                }
            }
 private static void MapGotoBookmark(Dictionary<String, Object> map, PdfObject dest, IntHashtable pages) 
 {
     if (dest.IsString())
         map["Named"] = dest.ToString();
     else if (dest.IsName())
         map["Named"] = PdfName.DecodeName(dest.ToString());
     else if (dest.IsArray()) 
         map["Page"] = MakeBookmarkParam((PdfArray)dest, pages); //changed by ujihara 2004-06-13
     map["Action"] = "GoTo";
 }
Exemple #18
0
 private void SerObject(PdfObject obj, int level, ByteBuffer bb) {
     if (level <= 0)
         return;
     if (obj == null) {
         bb.Append("$Lnull");
         return;
     }
     if (obj.IsIndirect()) {
         if (serialized.Contains(obj))
             return;
         else
             serialized.Add(obj);
     }
     obj = PdfReader.GetPdfObject(obj);
     if (obj.IsStream()) {
         bb.Append("$B");
         SerDic((PdfDictionary)obj, level - 1, bb);
         if (level > 0) {
             bb.Append(DigestAlgorithms.Digest("MD5", PdfReader.GetStreamBytesRaw((PRStream)obj)));
         }
     }
     else if (obj.IsDictionary()) {
         SerDic((PdfDictionary)obj, level - 1, bb);
     }
     else if (obj.IsArray()) {
         SerArray((PdfArray)obj, level - 1, bb);
     }
     else if (obj.IsString()) {
         bb.Append("$S").Append(obj.ToString());
     }
     else if (obj.IsName()) {
         bb.Append("$N").Append(obj.ToString());
     }
     else
         bb.Append("$L").Append(obj.ToString());
 }
Exemple #19
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);
        }
        private void fillMetrics(byte[] touni, IntHashtable widths, int dw)
        {
            PdfContentParser ps   = new PdfContentParser(new PrTokeniser(touni));
            PdfObject        ob   = null;
            PdfObject        last = null;

            while ((ob = ps.ReadPrObject()) != null)
            {
                if (ob.Type == PdfContentParser.COMMAND_TYPE)
                {
                    if (ob.ToString().Equals("beginbfchar"))
                    {
                        int n = ((PdfNumber)last).IntValue;
                        for (int k = 0; k < n; ++k)
                        {
                            string cid = decodeString((PdfString)ps.ReadPrObject());
                            string uni = decodeString((PdfString)ps.ReadPrObject());
                            if (uni.Length == 1)
                            {
                                int cidc = cid[0];
                                int unic = uni[uni.Length - 1];
                                int w    = dw;
                                if (widths.ContainsKey(cidc))
                                {
                                    w = widths[cidc];
                                }
                                _metrics[unic] = new[] { cidc, w };
                            }
                        }
                    }
                    else if (ob.ToString().Equals("beginbfrange"))
                    {
                        int n = ((PdfNumber)last).IntValue;
                        for (int k = 0; k < n; ++k)
                        {
                            string    cid1  = decodeString((PdfString)ps.ReadPrObject());
                            string    cid2  = decodeString((PdfString)ps.ReadPrObject());
                            int       cid1C = cid1[0];
                            int       cid2C = cid2[0];
                            PdfObject ob2   = ps.ReadPrObject();
                            if (ob2.IsString())
                            {
                                string uni = decodeString((PdfString)ob2);
                                if (uni.Length == 1)
                                {
                                    int unic = uni[uni.Length - 1];
                                    for (; cid1C <= cid2C; cid1C++, unic++)
                                    {
                                        int w = dw;
                                        if (widths.ContainsKey(cid1C))
                                        {
                                            w = widths[cid1C];
                                        }
                                        _metrics[unic] = new[] { cid1C, w };
                                    }
                                }
                            }
                            else
                            {
                                PdfArray a = (PdfArray)ob2;
                                for (int j = 0; j < a.Size; ++j, ++cid1C)
                                {
                                    string uni = decodeString(a.GetAsString(j));
                                    if (uni.Length == 1)
                                    {
                                        int unic = uni[uni.Length - 1];
                                        int w    = dw;
                                        if (widths.ContainsKey(cid1C))
                                        {
                                            w = widths[cid1C];
                                        }
                                        _metrics[unic] = new[] { cid1C, w };
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    last = ob;
                }
            }
        }