/// <summary>
    /// Removes an annotation from the document.
    /// </summary>
    public void Remove(PdfAnnotation annotation)
    {
      if (annotation.Owner != Owner)
        throw new InvalidOperationException("The annotation does not belong to this document.");

      Owner.Internals.RemoveObject(annotation);
      Elements.Remove(annotation.Reference);
    }
Example #2
0
        /// <summary>
        /// Gets the <see cref="PdfSharp.Pdf.Annotations.PdfAnnotation"/> with the specified title. Returns null if not found
        /// </summary>
        public PdfAnnotation this[string name]
        {
            get
            {
                if (_annotationsLookup.ContainsKey(name))
                {
                    return(_annotationsLookup[name]);
                }

                PdfReference  iref;
                PdfDictionary dict;
                for (int i = 0; i < Elements.Count; i++)
                {
                    if ((iref = Elements[i] as PdfReference) != null)
                    {
                        dict = (PdfDictionary)iref.Value;
                    }
                    else
                    {
                        dict = (PdfDictionary)Elements[i];
                    }
                    if (!string.Equals(name, dict.Elements.GetString(PdfAnnotation.Keys.T)))
                    {
                        continue;
                    }

                    // Found it. Track it for quicker lookup in the future.
                    PdfAnnotation annotation = dict as PdfAnnotation;
                    if (annotation == null)
                    {
                        annotation = new PdfGenericAnnotation(dict);
                        if (iref == null)
                        {
                            Elements[i] = annotation;
                        }
                    }
                    _annotationsLookup.Add(annotation.Title, annotation);
                    return(annotation);
                }

                return(null);
            }
        }
 /// <summary>
 /// Adds the specified annotation.
 /// </summary>
 /// <param name="annotation">The annotation.</param>
 public void Add(PdfAnnotation annotation)
 {
   annotation.Document = this.Owner;
   this.Owner.irefTable.Add(annotation);
   Elements.Add(annotation.Reference);
 }
Example #4
0
 /// <summary>
 /// Adds the specified annotation.
 /// </summary>
 /// <param name="annotation">The annotation.</param>
 public void Add(PdfAnnotation annotation)
 {
     annotation.Document = this.Owner;
     this.Owner.irefTable.Add(annotation);
     Elements.Add(annotation.Reference);
 }