/// <summary> /// Gets the <see cref="PdfSharp.Pdf.Annotations.PdfAnnotation"/> at the specified index. /// </summary> public PdfAnnotation this[int index] { get { PdfReference iref = null; PdfDictionary dict = null; PdfItem item = Elements[index]; if ((iref = item as PdfReference) != null) { Debug.Assert(iref.Value is PdfDictionary, "Reference to dictionary expected."); dict = (PdfDictionary)iref.Value; } else { Debug.Assert(item is PdfDictionary, "Dictionary expected."); dict = (PdfDictionary)item; } PdfAnnotation annotation = dict as PdfAnnotation; if (annotation == null) { annotation = new PdfGenericAnnotation(dict); if (iref == null) { Elements[index] = annotation; } } return(annotation); } }
/// <summary> /// Gets the <see cref="PdfSharp.Pdf.Annotations.PdfAnnotation"/> at the specified index. /// </summary> public PdfAnnotation this[int index] { get { PdfReference iref; PdfDictionary dict; PdfItem item = Elements[index]; if ((iref = item as PdfReference) != null) { Debug.Assert(iref.Value is PdfDictionary, "Reference to dictionary expected."); dict = (PdfDictionary)iref.Value; } else { Debug.Assert(item is PdfDictionary, "Dictionary expected."); dict = (PdfDictionary)item; } PdfAnnotation annotation = dict as PdfAnnotation; if (annotation == null) { if (dict.Elements.GetString(PdfAnnotation.Keys.Subtype) == "/Widget") { annotation = new PdfWidgetAnnotation(dict); } else if (dict.Elements.GetString(PdfAnnotation.Keys.Subtype) == "/Link") { annotation = new PdfLinkAnnotation(dict); } else if (dict.Elements.GetString(PdfAnnotation.Keys.Subtype) == "/Stamp") { annotation = new PdfRubberStampAnnotation(dict); } else if (dict.Elements.GetString(PdfAnnotation.Keys.Subtype) == "/Text") { annotation = new PdfTextAnnotation(dict); } else { annotation = new PdfGenericAnnotation(dict); } if (iref == null) { Elements[index] = annotation; } } return(annotation); } }
/// <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> /// Gets the <see cref="PdfSharp.Pdf.Annotations.PdfAnnotation"/> at the specified index. /// </summary> public PdfAnnotation this[int index] { get { PdfReference iref = null; PdfDictionary dict = null; PdfItem item = Elements[index]; if ((iref = item as PdfReference) != null) { Debug.Assert(iref.Value is PdfDictionary, "Reference to dictionary expected."); dict = (PdfDictionary)iref.Value; } else { Debug.Assert(item is PdfDictionary, "Dictionary expected."); dict = (PdfDictionary)item; } PdfAnnotation annotation = dict as PdfAnnotation; if (annotation == null) { annotation = new PdfGenericAnnotation(dict); if (iref == null) Elements[index] = annotation; } return annotation; } }