Example #1
0
        /// <summary>
        /// Adds the specified annotation to the collection.
        /// </summary>
        /// <param name="annotation">Annotation to be added.</param>
        public void Add(Annotation annotation)
        {
            if (annotation == null)
            {
                throw new ArgumentNullException();
            }

            Annotation copy = annotation.Clone(_owner, _page);

            _annotations.Add(copy);
            _array.AddItem(copy.Dictionary);

            if (annotation is MarkupAnnotation)
            {
                PopupAnnotation popup = (annotation as MarkupAnnotation).Popup;
                if (popup != null)
                {
                    Annotation popupClone = popup.Clone(_owner, _page);
                    (popupClone as PopupAnnotation).SetParent(copy);

                    copy.Dictionary.AddItem("Popup", popupClone.Dictionary);
                    _array.AddItem(popupClone.Dictionary);
                }
            }
            else if (annotation is Field)
            {
                if (_owner != null)
                {
                    _owner.AddField(copy as Field);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Removes the annotation with a specified index from the collection.
        /// </summary>
        /// <param name="index" href="http://msdn.microsoft.com/en-us/library/system.int32.aspx">The zero-based index of the annotation to be removed.</param>
        public void Remove(int index)
        {
            if (index < 0 || index >= Count)
            {
                throw new IndexOutOfRangeException();
            }

            Annotation annot = _annotations[index];

            _annotations.RemoveAt(index);

            remove(annot.Dictionary);
            if (annot is MarkupAnnotation)
            {
                PopupAnnotation popup = (annot as MarkupAnnotation).Popup;
                if (popup != null)
                {
                    remove(popup.Dictionary);
                }

                PDFDictionary currentDict = annot.Dictionary;
                for (int i = 0; i < _array.Count;)
                {
                    PDFDictionary dict = _array[i] as PDFDictionary;
                    PDFDictionary irt  = dict["IRT"] as PDFDictionary;
                    if (irt != null && irt == currentDict)
                    {
                        remove(dict);
                        PDFDictionary popupDict = dict["Popup"] as PDFDictionary;
                        if (popupDict != null)
                        {
                            remove(popupDict);
                        }

                        currentDict = dict;
                        i           = 0;
                    }
                    else
                    {
                        ++i;
                    }
                }
            }

            if (annot is Field && _owner != null)
            {
                _owner.RemoveField(annot as Field);
            }
        }