Ejemplo n.º 1
0
 public void Collect(XRef xref)
 {
     for (int i = 0; i < Count; ++i)
     {
         IPDFObject item = getItem(i);
         item.Collect(xref);
     }
 }
Ejemplo n.º 2
0
 public void AddItem(IPDFObject obj)
 {
     if (obj == null)
     {
         return;
     }
     _items.Add(obj);
 }
Ejemplo n.º 3
0
        internal static PDFDictionaryStream Copy(PDFDictionaryStream dictStream)
        {
            Stream stream = dictStream.GetStream();

            byte[] buf = new byte[stream.Length];
            stream.Position = 0;
            stream.Read(buf, 0, buf.Length);

            MemoryStream newStream = new MemoryStream();

            newStream.Write(buf, 0, buf.Length);

            PDFDictionary dict    = dictStream.Dictionary;
            PDFDictionary newDict = new PDFDictionary();

            string[] keys = { "Type", "Subtype", "FormType", "BBox", "Matrix", "Ref", "Metadata", "LastModified", "Name" };
            for (int i = 0; i < keys.Length; ++i)
            {
                IPDFObject obj = dict[keys[i]];
                if (obj != null)
                {
                    newDict.AddItem(keys[i], obj.Clone());
                }
            }

            PDFDictionary resources = dict["Resources"] as PDFDictionary;

            if (resources != null)
            {
                newDict.AddItem("Resources", ResourcesBase.Copy(resources));
            }

            PDFDictionary group = dict["Group"] as PDFDictionary;

            if (group != null)
            {
                newDict.AddItem("Group", GroupBase.Copy(group));
            }

            // PieceInfo, OPI, OC - still unknown
            // StructParent, StructParents - do not

            IPDFObject filter = dict["Filter"];

            if (filter != null)
            {
                newDict.AddItem("Filter", filter.Clone());
            }

            IPDFObject decodeParms = dict["DecodeParms"];

            if (decodeParms != null)
            {
                newDict.AddItem("DecodeParms", decodeParms.Clone());
            }

            return(new PDFDictionaryStream(newDict, newStream));
        }
Ejemplo n.º 4
0
        private void readPages(PDFArray kids, PDFArray newKids, IPDFObject resources, IPDFObject mediaBox, IPDFObject cropBox, IPDFObject rotate)
        {
            if (kids != null)
            {
                for (int i = 0; i < kids.Count; ++i)
                {
                    PDFDictionary dict = kids[i] as PDFDictionary;
                    if (dict != null)
                    {
                        PDFName type = dict["Type"] as PDFName;
                        if (type != null)
                        {
                            if (type.GetValue() == "Pages")
                            {
                                IPDFObject tmp = dict["Resources"];
                                if (tmp != null)
                                {
                                    resources = tmp;
                                }

                                tmp = dict["MediaBox"];
                                if (tmp != null)
                                {
                                    mediaBox = tmp;
                                }

                                tmp = dict["CropBox"];
                                if (tmp != null)
                                {
                                    cropBox = tmp;
                                }

                                tmp = dict["Rotate"];
                                if (tmp != null)
                                {
                                    rotate = tmp;
                                }

                                readPages(dict["Kids"] as PDFArray, newKids, resources, mediaBox, cropBox, rotate);
                            }
                            else if (type.GetValue() == "Page")
                            {
                                newKids.AddItem(dict);
                                dict.AddItem("Parent", GetDictionary());
                                dict.AddItemIfNotHave("Resources", resources);
                                dict.AddItemIfNotHave("MediaBox", mediaBox);
                                dict.AddItemIfNotHave("CropBox", cropBox);
                                dict.AddItemIfNotHave("Rotate", rotate);

                                Page page = new Page(dict, _owner);
                                _pages.Add(page);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        internal override Annotation Clone(IDocumentEssential owner, Page page)
        {
            if (Page == null)
            {
                ApplyOwner(owner);
                SetPage(page, true);
                return(this);
            }

            PDFDictionary res = AnnotationBase.Copy(Dictionary);
            IPDFObject    h   = Dictionary["H"];

            if (h != null)
            {
                res.AddItem("H", h.Clone());
            }

            PDFArray quadPoints = Dictionary["QuadPoints"] as PDFArray;

            if (quadPoints != null)
            {
                RectangleF oldRect;
                if (Page == null)
                {
                    oldRect = new RectangleF();
                }
                else
                {
                    oldRect = Page.PageRect;
                }

                res.AddItem("QuadPoints", CloneUtility.CopyArrayCoordinates(quadPoints, oldRect, page.PageRect, Page == null));
            }

            IPDFObject pa = Dictionary["PA"];

            if (pa != null)
            {
                res.AddItem("PA", pa.Clone());
            }

            LinkAnnotation annot = new LinkAnnotation(res, owner);

            if (_destination != null)
            {
                annot.Destination = Destination;
            }
            if (_action != null)
            {
                annot.Action = _action;
            }

            annot.SetPage(Page, false);
            annot.SetPage(page, true);
            return(annot);
        }
Ejemplo n.º 6
0
Archivo: PDF.cs Proyecto: jrhay/PKPDF
        /// <summary>
        /// Load a single object from the PDF data stream, starting at a paritcular offset
        /// </summary>
        /// <param name="Offset">Offset into data stream of object to read</param>
        /// <returns>Object as read out of data stream, or null if no object could be parsed</returns>
        private IPDFObject LoadObjectAtOffset(int Offset)
        {
            IPDFObject objectDefinition = PDFObjectParser.Parse(RawData, out _, Offset);

            if (objectDefinition.Type == PDFObjectType.ObjectDefinition)
            {
                return(((PDFObjectDefinition)objectDefinition).Object);
            }
            return(objectDefinition);
        }
Ejemplo n.º 7
0
        private void loadDestination()
        {
            IPDFObject dest = Dictionary["Dest"];

            if (dest == null)
            {
                return;
            }
            _destination = new Destination(dest, Owner);
        }
Ejemplo n.º 8
0
        private static void changeFont(ref TextState currentTextState, Resources resources, TextFont textFont)
        {
            IPDFObject obj = resources.GetResource(textFont.FontName, ResourceType.Font);

            if (obj is PDFDictionary)
            {
                currentTextState.FontBase = FontBase.Instance(obj as PDFDictionary);
            }
            currentTextState.FontSize = textFont.FontSize;
        }
Ejemplo n.º 9
0
        internal IPDFObject ParseEntry(int index, int offset, int genNo)
        {
            bool succes = false;

            if (offset >= 0)
            {
                _stream.Position = offset;
                int objNo = ReadInteger(out succes);
                if (succes)
                {
                    succes = (index == objNo);
                    if (succes)
                    {
                        ReadInteger(out succes);
                        if (succes)
                        {
                            ReadLexeme();
                            if (!CurrentLexemeEquals("obj"))
                            {
                                succes = false;
                            }
                        }
                    }
                }
            }

            if (!succes)
            {
                string s   = (char)256 + index.ToString() + " 0 obj";
                long   pos = FindSubstring(s, 0, _length);
                if (pos < 0)
                {
                    return(new PDFNull());
                }
                _stream.Position = pos + s.Length;
                _lastParsedByte  = _stream.ReadByte();
            }

            IPDFObject obj = readObject(_lastParsedByte, index, genNo);

            if (obj is PDFDictionary)
            {
                if (IsEOL(_lastParsedByte))
                {
                    SkipEOL();
                }
                if (_lastParsedByte == 's')
                {
                    return(parseStream(obj as PDFDictionary, index, genNo));
                }
            }

            return(obj);
        }
Ejemplo n.º 10
0
 internal static void Copy(PDFDictionary sourceDict, PDFDictionary destinationDict)
 {
     string[] keys = { "Opt", "TI", "I", "Q", "RV" };
     for (int i = 0; i < keys.Length; ++i)
     {
         IPDFObject obj = sourceDict[keys[i]];
         if (obj != null)
         {
             destinationDict.AddItem(keys[i], obj.Clone());
         }
     }
 }
Ejemplo n.º 11
0
Archivo: PDF.cs Proyecto: jrhay/PKPDF
 /// <summary>
 /// Reads the PDF catalog dictionary, if it can be found
 /// </summary>
 /// <returns>TRUE if catalog dictionary found and loaded successfully, FALSE otherwise</returns>
 private bool ReadPDFCatalog()
 {
     Catalog = null;
     if ((Trailer != null) && (Trailer.Keys.Contains("Root")))
     {
         IPDFObject catalogObject = GetObject(Trailer["Root"]);
         if ((catalogObject != null) && (catalogObject.Type == PDFObjectType.Dictionary))
         {
             Catalog = (PDFDictionary)catalogObject;
         }
     }
     return(Catalog != null);
 }
Ejemplo n.º 12
0
        internal static IPDFObject Copy(IPDFObject obj)
        {
            IPDFObject result;

            if (obj is PDFDictionary)
            {
                result = new PDFDictionary();
                (result as PDFDictionary).AddItem("Type", new PDFName("3DRef"));
                IPDFObject threedd = (obj as PDFDictionary)["3DD"];
                (result as PDFDictionary).AddItem("3DD", threedd);
                return(result);
            }

            return(obj);
        }
Ejemplo n.º 13
0
        public bool Contains(IPDFObject obj, out string key)
        {
            int count = _items.Count;

            for (int i = 0; i < count; ++i)
            {
                if (_items[i].Value == obj)
                {
                    key = _items[i].Key;
                    return(true);
                }
            }
            key = "";
            return(false);
        }
Ejemplo n.º 14
0
        internal static void CopyTo(PDFDictionary sourceDict, PDFDictionary destinationDict)
        {
            string[] keys = { "Open", "T", "CA", "CreationDate", "Subj", "RT", "RC" };
            for (int i = 0; i < keys.Length; ++i)
            {
                IPDFObject obj = sourceDict[keys[i]];
                if (obj != null)
                {
                    destinationDict.AddItem(keys[i], obj.Clone());
                }
            }

            //Popup - need set after adding
            //IRT, ExData - TODO
        }
Ejemplo n.º 15
0
        private IPDFObject getItem(int index)
        {
            if (index < _items.Count && index >= 0)
            {
                IPDFObject obj = _items[index];
                if (obj is PDFLink)
                {
                    obj = (obj as PDFLink).GetValue();
                    _items.RemoveAt(index);
                    _items.Insert(index, obj);
                }
                return(obj);
            }

            return(null);
        }
Ejemplo n.º 16
0
        internal static PDFDictionary Copy(PDFDictionary dict)
        {
            PDFDictionary newDict = new PDFDictionary();

            string[] keys = { "Type", "S", "D", "Dm", "M", "Di", "SS", "B" };
            for (int i = 0; i < keys.Length; ++i)
            {
                IPDFObject val = dict[keys[i]];
                if (val != null)
                {
                    newDict.AddItem(keys[i], val.Clone());
                }
            }

            return(newDict);
        }
Ejemplo n.º 17
0
        internal static PDFDictionary Copy(PDFDictionary dict)
        {
            PDFDictionary result = new PDFDictionary();

            string[] keys = { "Type", "U", "C", "F", "D", "FD", "RT", "RD", "PS", "SS", "O" };
            for (int i = 0; i < keys.Length; ++i)
            {
                IPDFObject obj = dict[keys[i]];
                if (obj != null)
                {
                    result.AddItem(keys[i], obj.Clone());
                }
            }

            return(result);
        }
Ejemplo n.º 18
0
        internal static PDFDictionary Copy(PDFDictionary dict)
        {
            PDFDictionary result = new PDFDictionary();

            string[] keys = { "Start", "Duration", "Rate", "Volume", "ShowControls", "Mode", "Synchronous", "FWScale", "FWPosition" };
            for (int i = 0; i < keys.Length; ++i)
            {
                IPDFObject obj = dict[keys[i]];
                if (obj != null)
                {
                    result.AddItem(keys[i], obj.Clone());
                }
            }

            return(result);
        }
Ejemplo n.º 19
0
        public void Write(SaveParameters param)
        {
            Stream stream = param.Stream;

            stream.WriteByte((byte)'<');
            stream.WriteByte((byte)'<');

            int count = _items.Count;

            for (int i = 0; i < count; ++i)
            {
                KeyValuePair <string, IPDFObject> pair = _items[i];
                PDFName.Write(stream, pair.Key);

                stream.WriteByte((byte)' ');

                IPDFObject val = pair.Value;
                if (val is PDFDictionary || val is PDFDictionaryStream)
                {
                    if (!param.WriteInheritableObjects)
                    {
                        StringUtility.WriteToStream(val.ObjNo, stream);
                        stream.WriteByte((byte)' ');
                        stream.WriteByte((byte)'0');
                        stream.WriteByte((byte)' ');
                        stream.WriteByte((byte)'R');
                    }
                    else
                    {
                        val.Write(param);
                    }
                }
                else
                {
                    val.Write(param);
                }

                if (i != count - 1)
                {
                    stream.WriteByte((byte)'\n');
                }
            }

            stream.WriteByte((byte)'>');
            stream.WriteByte((byte)'>');
        }
Ejemplo n.º 20
0
        public PDFArray GetDestinationFromNames(string name)
        {
            IPDFObject dest = _catalog.Names.Destinations.GetItem(name);

            if (dest != null)
            {
                if (dest is PDFArray)
                {
                    return(dest as PDFArray);
                }
                else if (dest is PDFDictionary)
                {
                    return((dest as PDFDictionary)["D"] as PDFArray);
                }
            }
            return(null);
        }
Ejemplo n.º 21
0
        internal override Annotation Clone(IDocumentEssential owner, Page page)
        {
            PDFDictionary res = AnnotationBase.Copy(Dictionary);

            IPDFObject open = Dictionary["Open"];

            if (open != null)
            {
                res.AddItem("Open", open.Clone());
            }

            PopupAnnotation annot = new PopupAnnotation(res, owner);

            annot.SetPage(Page, false);
            annot.SetPage(page, true);
            return(annot);
        }
Ejemplo n.º 22
0
        internal override Annotation Clone(IDocumentEssential owner, Page page)
        {
            if (Page == null)
            {
                ApplyOwner(owner);
                SetPage(page, true);
                return(this);
            }

            PDFDictionary res = AnnotationBase.Copy(Dictionary);

            IPDFObject t = Dictionary["T"];

            if (t != null)
            {
                res.AddItem("T", t.Clone());
            }

            PDFDictionary movie = Dictionary["Movie"] as PDFDictionary;

            if (movie != null)
            {
                res.AddItem("Movie", MovieBase.Copy(movie));
            }

            IPDFObject a = Dictionary["A"];

            if (a != null)
            {
                if (a is PDFBoolean)
                {
                    res.AddItem("A", a.Clone());
                }
                else if (a is PDFDictionary)
                {
                    res.AddItem("A", MovieActivationBase.Copy(a as PDFDictionary));
                }
            }

            MovieAnnotation annot = new MovieAnnotation(res, owner);

            annot.SetPage(Page, false);
            annot.SetPage(page, true);
            return(annot);
        }
Ejemplo n.º 23
0
 private void removeFromKids(PDFArray kids, IPDFObject key)
 {
     for (int i = 0; i < kids.Count; ++i)
     {
         PDFDictionary dict = kids[i] as PDFDictionary;
         if (dict != null)
         {
             PDFArray limits = dict["Limits"] as PDFArray;
             if (limits != null)
             {
                 if (isHitInRange(limits, key))
                 {
                     removeItem(dict, key);
                 }
             }
         }
     }
 }
Ejemplo n.º 24
0
        private void removeItem(PDFDictionary dict, IPDFObject key)
        {
            PDFArray values = dict[NodeType] as PDFArray;

            if (values != null)
            {
                deleteItem(values, key);
                return;
            }

            PDFArray kids = dict["Kids"] as PDFArray;

            if (kids != null)
            {
                removeFromKids(kids, key);
                return;
            }
        }
Ejemplo n.º 25
0
 private void insertIntoKids(PDFArray kids, IPDFObject key, IPDFObject value)
 {
     for (int i = 0; i < kids.Count; ++i)
     {
         PDFDictionary dict = kids[i] as PDFDictionary;
         if (dict != null)
         {
             PDFArray limits = dict["Limits"] as PDFArray;
             if (limits != null)
             {
                 if (isHitInRange(limits, key))
                 {
                     insertItem(dict, key, value);
                 }
             }
         }
     }
 }
Ejemplo n.º 26
0
        private IPDFObject getItem(string key)
        {
            int count = _items.Count;

            for (int i = 0; i < count; ++i)
            {
                if (_items[i].Key == key)
                {
                    IPDFObject obj = _items[i].Value;
                    if (obj is PDFLink)
                    {
                        _items[i] = new KeyValuePair <string, IPDFObject>(key, (obj as PDFLink).GetValue());
                    }
                    return(_items[i].Value);
                }
            }
            return(null);
        }
Ejemplo n.º 27
0
        private PDFDictionary parseDictionary(int objNo, int genNo)
        {
            PDFDictionary dict = new PDFDictionary();
            int           b    = _stream.ReadByte();

            for (; ;)
            {
                if (IsEOL(b))
                {
                    SkipEOL();
                    b = _lastParsedByte;
                }
                if (b == '%')
                {
                    ReadComment();
                    b = _lastParsedByte;
                    continue;
                }

                if (b == '>')
                {
                    break;
                }
                if (b != '/')
                {
                    return(null);
                }

                string     key = readNameBytes();
                IPDFObject obj = readObject(_lastParsedByte, objNo, genNo);
                b = _lastParsedByte;

                if (obj == null)
                {
                    return(null);
                }
                dict.AddItem(key, obj);
            }

            _stream.ReadByte();
            _lastParsedByte = _stream.ReadByte();
            return(dict);
        }
Ejemplo n.º 28
0
        private void parseKids(PDFDictionary dict)
        {
            IPDFObject resources = dict["Resources"];
            IPDFObject mediaBox  = dict["MediaBox"];
            IPDFObject cropBox   = dict["CropBox"];
            IPDFObject rotate    = dict["Rotate"];

            PDFArray kids    = _dictionary["Kids"] as PDFArray;
            PDFArray newKids = new PDFArray();

            readPages(kids, newKids, resources, mediaBox, cropBox, rotate);

            dict.RemoveItem("Resources");
            dict.RemoveItem("MediaBox");
            dict.RemoveItem("CropBox");
            dict.RemoveItem("Rotate");

            dict.AddItem("Kids", newKids);
        }
Ejemplo n.º 29
0
        public void AddItemIfNotHave(string key, IPDFObject value)
        {
            if (value == null)
            {
                return;
            }

            int count = _items.Count;

            for (int i = 0; i < count; ++i)
            {
                KeyValuePair <string, IPDFObject> pair = _items[i];
                if (pair.Key == key)
                {
                    return;
                }
            }
            _items.Add(new KeyValuePair <string, IPDFObject>(key, value));
        }
Ejemplo n.º 30
0
        internal static void CopyTo(PDFDictionary sourceDict, PDFDictionary destinationDict)
        {
            string[] keys = { "IC", "BE", "RD" };
            for (int i = 0; i < keys.Length; ++i)
            {
                IPDFObject obj = sourceDict[keys[i]];
                if (obj != null)
                {
                    destinationDict.AddItem(keys[i], obj.Clone());
                }
            }

            PDFDictionary bs = sourceDict["BS"] as PDFDictionary;

            if (bs != null)
            {
                destinationDict.AddItem("BS", AnnotationBorderStyle.Copy(bs));
            }
        }