Пример #1
0
        /**
         * Adds new content object before the existing content objects.
         * The original code was provided by Stefan Ostermann author of ScribMaster and HandWrite Pro.
         * Additional code to handle PDFs with indirect array of stream objects was written by EDragoev.
         *
         * @param content
         * @param objects
         */
        public void AddPrefixContent(byte[] content, List <PDFobj> objects)
        {
            PDFobj obj = new PDFobj();

            obj.SetNumber(objects.Count + 1);
            obj.SetStream(content);
            objects.Add(obj);

            String objNumber = obj.number.ToString();

            for (int i = 0; i < dict.Count; i++)
            {
                if (dict[i].Equals("/Contents"))
                {
                    i += 1;
                    String token = dict[i];
                    if (token.Equals("["))
                    {
                        // Array of content object streams
                        i += 1;
                        dict.Insert(i, "R");
                        dict.Insert(i, "0");
                        dict.Insert(i, objNumber);
                        return;
                    }
                    else
                    {
                        // Single content object
                        PDFobj obj2 = objects[Int32.Parse(token) - 1];
                        if (obj2.data == null && obj2.stream == null)
                        {
                            // This is not a stream object!
                            for (int j = 0; j < obj2.dict.Count; j++)
                            {
                                if (obj2.dict[j].Equals("["))
                                {
                                    j += 1;
                                    obj2.dict.Insert(j, "R");
                                    obj2.dict.Insert(j, "0");
                                    obj2.dict.Insert(j, objNumber);
                                    return;
                                }
                            }
                        }
                        dict.Insert(i, "[");
                        dict.Insert(i + 4, "]");
                        i += 1;
                        dict.Insert(i, "R");
                        dict.Insert(i, "0");
                        dict.Insert(i, objNumber);
                        return;
                    }
                }
            }
        }
Пример #2
0
        public void AddContent(byte[] content, SortedDictionary <Int32, PDFobj> objects)
        {
            PDFobj obj = new PDFobj();

            int maxObjNumber = -1;

            foreach (int number in objects.Keys)
            {
                if (number > maxObjNumber)
                {
                    maxObjNumber = number;
                }
            }
            obj.SetNumber(maxObjNumber + 1);

            obj.SetStream(content);
            objects.Add(obj.GetNumber(), obj);

            int  index  = -1;
            bool single = false;

            for (int i = 0; i < dict.Count; i++)
            {
                if (dict[i].Equals("/Contents"))
                {
                    String str = dict[++i];
                    if (str.Equals("["))
                    {
                        for (;;)
                        {
                            str = dict[++i];
                            if (str.Equals("]"))
                            {
                                index = i;
                                break;
                            }
                            ++i; // 0
                            ++i; // R
                        }
                    }
                    else
                    {
                        // Single content object
                        index  = i;
                        single = true;
                    }
                    break;
                }
            }

            if (single)
            {
                dict.Insert(index, "[");
                dict.Insert(index + 4, "]");
                dict.Insert(index + 4, "R");
                dict.Insert(index + 4, "0");
                dict.Insert(index + 4, obj.number.ToString());
            }
            else
            {
                dict.Insert(index, "R");
                dict.Insert(index, "0");
                dict.Insert(index, obj.number.ToString());
            }
        }
Пример #3
0
        /**
         * Adds new content object before the existing content objects.
         * The original code was provided by Stefan Ostermann author of ScribMaster and HandWrite Pro.
         * Additional code to handle PDFs with indirect array of stream objects was written by EDragoev.
         *
         * @param content
         * @param objects
         */
        public void AddPrefixContent(
            byte[] content, SortedDictionary <Int32, PDFobj> objects)
        {
            PDFobj obj          = new PDFobj();
            int    maxObjNumber = -1;

            foreach (int number in objects.Keys)
            {
                if (number > maxObjNumber)
                {
                    maxObjNumber = number;
                }
            }
            obj.SetNumber(maxObjNumber + 1);
            obj.SetStream(content);
            objects[obj.GetNumber()] = obj;

            String objNumber = obj.number.ToString();

            for (int i = 0; i < dict.Count; i++)
            {
                if (dict[i].Equals("/Contents"))
                {
                    i += 1;
                    String token = dict[i];
                    if (token.Equals("["))
                    {
                        // Array of content object streams
                        i += 1;
                        dict.Insert(i, "R");
                        dict.Insert(i, "0");
                        dict.Insert(i, objNumber);
                        return;
                    }
                    else
                    {
                        // Single content object
                        PDFobj obj2 = objects[Int32.Parse(token)];
                        if (obj2.data == null && obj2.stream == null)
                        {
                            // This is not a stream object!
                            for (int j = 0; j < obj2.dict.Count; j++)
                            {
                                if (obj2.dict[j].Equals("["))
                                {
                                    j += 1;
                                    obj2.dict.Insert(j, "R");
                                    obj2.dict.Insert(j, "0");
                                    obj2.dict.Insert(j, objNumber);
                                    return;
                                }
                            }
                        }
                        dict.Insert(i, "[");
                        dict.Insert(i + 4, "]");
                        i += 1;
                        dict.Insert(i, "R");
                        dict.Insert(i, "0");
                        dict.Insert(i, objNumber);
                        return;
                    }
                }
            }
        }
Пример #4
0
        public void AddContent(byte[] content, SortedDictionary<Int32, PDFobj> objects)
        {
            PDFobj obj = new PDFobj();

            int maxObjNumber = -1;
            foreach (int number in objects.Keys) {
            if (number > maxObjNumber) { maxObjNumber = number; }
            }
            obj.SetNumber(maxObjNumber + 1);

            obj.SetStream(content);
            objects.Add(obj.GetNumber(), obj);

            int index = -1;
            bool single = false;
            for (int i = 0; i < dict.Count; i++) {
            if (dict[i].Equals("/Contents")) {
                String str = dict[++i];
                if (str.Equals("[")) {
                    for (;;) {
                        str = dict[++i];
                        if (str.Equals("]")) {
                            index = i;
                            break;
                        }
                        ++i;    // 0
                        ++i;    // R
                    }
                }
                else {
                    // Single content object
                    index = i;
                    single = true;
                }
                break;
            }
            }

            if (single) {
            dict.Insert(index, "[");
            dict.Insert(index + 4, "]");
            dict.Insert(index + 4, "R");
            dict.Insert(index + 4, "0");
            dict.Insert(index + 4, obj.number.ToString());
            }
            else {
            dict.Insert(index, "R");
            dict.Insert(index, "0");
            dict.Insert(index, obj.number.ToString());
            }
        }