コード例 #1
0
ファイル: PdfTextField.cs プロジェクト: mapilab/PDFsharp
        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));
        }
コード例 #2
0
        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);
        }
コード例 #3
0
            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);
                    }
                }
            }
コード例 #4
0
ファイル: PdfAcroField.cs プロジェクト: t00/PdfSharpXps
 /// <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);
     }
 }
コード例 #5
0
ファイル: PdfAcroForm.cs プロジェクト: mapilab/PDFsharp
        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);
                }
            }
        }
コード例 #6
0
ファイル: PdfAcroField.cs プロジェクト: t00/PdfSharpXps
            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);
            }
コード例 #7
0
        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);
        }