internal XFont GetFontFromElement(PdfAcroField element) { string[] name = element.Font.FamilyName.Split(','); double size = element.Font.Size; XFontStyle style; if (name.Length > 1) { switch (name[1]) { case "Bold": style = XFontStyle.Bold; break; case "Italic": style = XFontStyle.Italic; break; case "BoldItalic": style = XFontStyle.BoldItalic; break; default: style = XFontStyle.Regular; break; } } else { style = XFontStyle.Regular; } return(new XFont(name[0], size, style)); }
public void AddKid(PdfAcroField kid) { if (kid.Elements.ContainsKey(Keys.Parent)) { throw new ArgumentException("Field already belongs to another parent."); } Fields.Add(kid, this.Page); kid.Elements.SetReference(Keys.Parent, this.Reference); }
internal void GetDescendantNames(ref List <string> names, string partialName) { int count = Elements.Count; for (int idx = 0; idx < count; idx++) { PdfAcroField field = this[idx]; if (field != null) { field.GetDescendantNames(ref names, partialName); } } }
/// <summary> /// Gets a field from the collection. For your convenience an instance of a derived class like /// PdfTextField or PdfCheckBox is returned if PDFsharp can guess the actual type of the dictionary. /// If the actual type cannot be guessed by PDFsharp the function returns an instance /// of PdfGenericField. /// </summary> public PdfAcroField this[int index] { get { PdfItem item = Elements[index]; Debug.Assert(item is PdfReference); PdfDictionary dict = ((PdfReference)item).Value as PdfDictionary; Debug.Assert(dict != null); PdfAcroField field = dict as PdfAcroField; if (field == null && dict != null) { // Do type transformation field = CreateAcroField(dict); //Elements[index] = field.XRef; } return(field); } }
public IEnumerable <PdfAcroField> WalkAllFields(PdfAcroField current) { if (!current.HasKids) { yield return(current); yield break; } foreach (var child in current.Fields) { var subchildren = WalkAllFields(child); foreach (var subChild in subchildren) { yield return(subChild); } } }
internal PdfAcroField GetValue(string name) { if (name == null || name.Length == 0) { return(null); } int dot = name.IndexOf('.'); string prefix = dot == -1 ? name : name.Substring(0, dot); string suffix = dot == -1 ? "" : name.Substring(dot + 1); int count = Elements.Count; for (int idx = 0; idx < count; idx++) { PdfAcroField field = this[idx]; if (field.Name == prefix) { return(field.GetValue(suffix)); } } return(null); }
private PdfReference FindPageRefInChilds(PdfAcroField startField) { var pageRef = startField.Elements.GetReference(Keys.Page); if (pageRef != null) { return(pageRef); } for (var i = 0; i < startField.Fields.Names.Length; i++) { var child = startField.Fields[i]; pageRef = child.Elements.GetReference(Keys.Page); if (pageRef != null) { return(pageRef); } pageRef = FindPageRefInChilds(child); if (pageRef != null) { return(pageRef); } } return(null); }