Test
This commit is contained in:
		
							
								
								
									
										579
									
								
								PrintPDF/PdfSharp/Pdf.AcroForms/PdfAcroField.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										579
									
								
								PrintPDF/PdfSharp/Pdf.AcroForms/PdfAcroField.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,579 @@
 | 
			
		||||
#region PDFsharp - A .NET library for processing PDF
 | 
			
		||||
//
 | 
			
		||||
// Authors:
 | 
			
		||||
//   Stefan Lange
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2005-2017 empira Software GmbH, Cologne Area (Germany)
 | 
			
		||||
//
 | 
			
		||||
// http://www.pdfsharp.com
 | 
			
		||||
// http://sourceforge.net/projects/pdfsharp
 | 
			
		||||
//
 | 
			
		||||
// Permission is hereby granted, free of charge, to any person obtaining a
 | 
			
		||||
// copy of this software and associated documentation files (the "Software"),
 | 
			
		||||
// to deal in the Software without restriction, including without limitation
 | 
			
		||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
 | 
			
		||||
// and/or sell copies of the Software, and to permit persons to whom the
 | 
			
		||||
// Software is furnished to do so, subject to the following conditions:
 | 
			
		||||
//
 | 
			
		||||
// The above copyright notice and this permission notice shall be included
 | 
			
		||||
// in all copies or substantial portions of the Software.
 | 
			
		||||
//
 | 
			
		||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 | 
			
		||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 | 
			
		||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 | 
			
		||||
// DEALINGS IN THE SOFTWARE.
 | 
			
		||||
#endregion
 | 
			
		||||
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Diagnostics;
 | 
			
		||||
using PdfSharp.Pdf.Advanced;
 | 
			
		||||
 | 
			
		||||
namespace PdfSharp.Pdf.AcroForms
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Represents the base class for all interactive field dictionaries.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public abstract class PdfAcroField : PdfDictionary
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Initializes a new instance of PdfAcroField.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        internal PdfAcroField(PdfDocument document)
 | 
			
		||||
            : base(document)
 | 
			
		||||
        { }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Initializes a new instance of the <see cref="PdfAcroField"/> class. Used for type transformation.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        protected PdfAcroField(PdfDictionary dict)
 | 
			
		||||
            : base(dict)
 | 
			
		||||
        { }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the name of this field.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string Name
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                string name = Elements.GetString(Keys.T);
 | 
			
		||||
                return name;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the field flags of this instance.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public PdfAcroFieldFlags Flags
 | 
			
		||||
        {
 | 
			
		||||
            // TODO: This entry is inheritable, thus the implementation is incorrect...
 | 
			
		||||
            get { return (PdfAcroFieldFlags)Elements.GetInteger(Keys.Ff); }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        internal PdfAcroFieldFlags SetFlags
 | 
			
		||||
        {
 | 
			
		||||
            get { return (PdfAcroFieldFlags)Elements.GetInteger(Keys.Ff); }
 | 
			
		||||
            set { Elements.SetInteger(Keys.Ff, (int)value); }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the value of the field.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public virtual PdfItem Value
 | 
			
		||||
        {
 | 
			
		||||
            get { return Elements[Keys.V]; }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                if (ReadOnly)
 | 
			
		||||
                    throw new InvalidOperationException("The field is read only.");
 | 
			
		||||
                if (value is PdfString || value is PdfName)
 | 
			
		||||
                    Elements[Keys.V] = value;
 | 
			
		||||
                else
 | 
			
		||||
                    throw new NotImplementedException("Values other than string cannot be set.");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets a value indicating whether the field is read only.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public bool ReadOnly
 | 
			
		||||
        {
 | 
			
		||||
            get { return (Flags & PdfAcroFieldFlags.ReadOnly) != 0; }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                if (value)
 | 
			
		||||
                    SetFlags |= PdfAcroFieldFlags.ReadOnly;
 | 
			
		||||
                else
 | 
			
		||||
                    SetFlags &= ~PdfAcroFieldFlags.ReadOnly;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the field with the specified name.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public PdfAcroField this[string name]
 | 
			
		||||
        {
 | 
			
		||||
            get { return GetValue(name); }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets a child field by name.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        protected virtual PdfAcroField GetValue(string name)
 | 
			
		||||
        {
 | 
			
		||||
            if (String.IsNullOrEmpty(name))
 | 
			
		||||
                return this;
 | 
			
		||||
            if (HasKids)
 | 
			
		||||
                return Fields.GetValue(name);
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Indicates whether the field has child fields.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public bool HasKids
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                PdfItem item = Elements[Keys.Kids];
 | 
			
		||||
                if (item == null)
 | 
			
		||||
                    return false;
 | 
			
		||||
                if (item is PdfArray)
 | 
			
		||||
                    return ((PdfArray)item).Elements.Count > 0;
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the names of all descendants of this field.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        [Obsolete("Use GetDescendantNames")]
 | 
			
		||||
        public string[] DescendantNames  // Properties should not return arrays.
 | 
			
		||||
        {
 | 
			
		||||
            get { return GetDescendantNames(); }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the names of all descendants of this field.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string[] GetDescendantNames()
 | 
			
		||||
        {
 | 
			
		||||
            List<string> names = new List<string>();
 | 
			
		||||
            if (HasKids)
 | 
			
		||||
            {
 | 
			
		||||
                PdfAcroFieldCollection fields = Fields;
 | 
			
		||||
                fields.GetDescendantNames(ref names, null);
 | 
			
		||||
            }
 | 
			
		||||
            List<string> temp = new List<string>();
 | 
			
		||||
            foreach (string name in names)
 | 
			
		||||
                temp.Add(name);
 | 
			
		||||
            return temp.ToArray();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the names of all appearance dictionaries of this AcroField.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string[] GetAppearanceNames()
 | 
			
		||||
        {
 | 
			
		||||
            Dictionary<string, object> names = new Dictionary<string, object>();
 | 
			
		||||
            PdfDictionary dict = Elements["/AP"] as PdfDictionary;
 | 
			
		||||
            if (dict != null)
 | 
			
		||||
            {
 | 
			
		||||
                AppDict(dict, names);
 | 
			
		||||
 | 
			
		||||
                if (HasKids)
 | 
			
		||||
                {
 | 
			
		||||
                    PdfItem[] kids = Fields.Elements.Items;
 | 
			
		||||
                    foreach (PdfItem pdfItem in kids)
 | 
			
		||||
                    {
 | 
			
		||||
                        if (pdfItem is PdfReference)
 | 
			
		||||
                        {
 | 
			
		||||
                            PdfDictionary xxx = ((PdfReference)pdfItem).Value as PdfDictionary;
 | 
			
		||||
                            if (xxx != null)
 | 
			
		||||
                                AppDict(xxx, names);
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    //((PdfDictionary)(((PdfReference)(Fields.Elements.Items[1])).Value)).Elements.SetName(Keys.V, name1);
 | 
			
		||||
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            string[] array = new string[names.Count];
 | 
			
		||||
            names.Keys.CopyTo(array, 0);
 | 
			
		||||
            return array;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //static string[] AppearanceNames(PdfDictionary dictIn)
 | 
			
		||||
        //{
 | 
			
		||||
        //  Dictionary<string, object> names = new Dictionary<string, object>();
 | 
			
		||||
        //  PdfDictionary dict = dictIn["/AP"] as PdfDictionary;
 | 
			
		||||
        //  if (dict != null)
 | 
			
		||||
        //  {
 | 
			
		||||
        //    AppDict(dict, names);
 | 
			
		||||
 | 
			
		||||
        //    if (HasKids)
 | 
			
		||||
        //    {
 | 
			
		||||
        //      PdfItem[] kids = Fields.Elements.Items;
 | 
			
		||||
        //      foreach (PdfItem pdfItem in kids)
 | 
			
		||||
        //      {
 | 
			
		||||
        //        if (pdfItem is PdfReference)
 | 
			
		||||
        //        {
 | 
			
		||||
        //          PdfDictionary xxx = ((PdfReference)pdfItem).Value as PdfDictionary;
 | 
			
		||||
        //          if (xxx != null)
 | 
			
		||||
        //            AppDict(xxx, names);
 | 
			
		||||
        //        }
 | 
			
		||||
        //      }
 | 
			
		||||
        //      //((PdfDictionary)(((PdfReference)(Fields.Elements.Items[1])).Value)).Elements.SetName(Keys.V, name1);
 | 
			
		||||
 | 
			
		||||
        //    }
 | 
			
		||||
        //  }
 | 
			
		||||
        //  string[] array = new string[names.Count];
 | 
			
		||||
        //  names.Keys.CopyTo(array, 0);
 | 
			
		||||
        //  return array;
 | 
			
		||||
        //}
 | 
			
		||||
 | 
			
		||||
        static void AppDict(PdfDictionary dict, Dictionary<string, object> names)
 | 
			
		||||
        {
 | 
			
		||||
            PdfDictionary sub;
 | 
			
		||||
            if ((sub = dict.Elements["/D"] as PdfDictionary) != null)
 | 
			
		||||
                AppDict2(sub, names);
 | 
			
		||||
            if ((sub = dict.Elements["/N"] as PdfDictionary) != null)
 | 
			
		||||
                AppDict2(sub, names);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        static void AppDict2(PdfDictionary dict, Dictionary<string, object> names)
 | 
			
		||||
        {
 | 
			
		||||
            foreach (string key in dict.Elements.Keys)
 | 
			
		||||
            {
 | 
			
		||||
                if (!names.ContainsKey(key))
 | 
			
		||||
                    names.Add(key, null);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        internal virtual void GetDescendantNames(ref List<string> names, string partialName)
 | 
			
		||||
        {
 | 
			
		||||
            if (HasKids)
 | 
			
		||||
            {
 | 
			
		||||
                PdfAcroFieldCollection fields = Fields;
 | 
			
		||||
                string t = Elements.GetString(Keys.T);
 | 
			
		||||
                Debug.Assert(t != "");
 | 
			
		||||
                if (t.Length > 0)
 | 
			
		||||
                {
 | 
			
		||||
                    if (!String.IsNullOrEmpty(partialName))
 | 
			
		||||
                        partialName += "." + t;
 | 
			
		||||
                    else
 | 
			
		||||
                        partialName = t;
 | 
			
		||||
                    fields.GetDescendantNames(ref names, partialName);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                string t = Elements.GetString(Keys.T);
 | 
			
		||||
                Debug.Assert(t != "");
 | 
			
		||||
                if (t.Length > 0)
 | 
			
		||||
                {
 | 
			
		||||
                    if (!String.IsNullOrEmpty(partialName))
 | 
			
		||||
                        names.Add(partialName + "." + t);
 | 
			
		||||
                    else
 | 
			
		||||
                        names.Add(t);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the collection of fields within this field.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public PdfAcroFieldCollection Fields
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                if (_fields == null)
 | 
			
		||||
                {
 | 
			
		||||
                    object o = Elements.GetValue(Keys.Kids, VCF.CreateIndirect);
 | 
			
		||||
                    _fields = (PdfAcroFieldCollection)o;
 | 
			
		||||
                }
 | 
			
		||||
                return _fields;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        PdfAcroFieldCollection _fields;
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Holds a collection of interactive fields.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public sealed class PdfAcroFieldCollection : PdfArray
 | 
			
		||||
        {
 | 
			
		||||
            PdfAcroFieldCollection(PdfArray array)
 | 
			
		||||
                : base(array)
 | 
			
		||||
            { }
 | 
			
		||||
 | 
			
		||||
            /// <summary>  
 | 
			
		||||
            /// Gets the number of elements in the array.  
 | 
			
		||||
            /// </summary>  
 | 
			
		||||
            public int Count
 | 
			
		||||
            {
 | 
			
		||||
                get
 | 
			
		||||
                {
 | 
			
		||||
                    return Elements.Count;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// Gets the names of all fields in the collection.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            public string[] Names
 | 
			
		||||
            {
 | 
			
		||||
                get
 | 
			
		||||
                {
 | 
			
		||||
                    int count = Elements.Count;
 | 
			
		||||
                    string[] names = new string[count];
 | 
			
		||||
                    for (int idx = 0; idx < count; idx++)
 | 
			
		||||
                        names[idx] = ((PdfDictionary)((PdfReference)Elements[idx]).Value).Elements.GetString(Keys.T);
 | 
			
		||||
                    return names;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// Gets an array of all descendant names.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            public string[] DescendantNames
 | 
			
		||||
            {
 | 
			
		||||
                get
 | 
			
		||||
                {
 | 
			
		||||
                    List<string> names = new List<string>();
 | 
			
		||||
                    GetDescendantNames(ref names, null);
 | 
			
		||||
                    //List<string> temp = new List<string>();
 | 
			
		||||
                    //foreach (PdfName name in names)
 | 
			
		||||
                    //  temp.Add(name.ToString());
 | 
			
		||||
                    return names.ToArray();
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            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;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// Gets the field with the specified name.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            public PdfAcroField this[string name]
 | 
			
		||||
            {
 | 
			
		||||
                get { return GetValue(name); }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            internal PdfAcroField GetValue(string name)
 | 
			
		||||
            {
 | 
			
		||||
                if (String.IsNullOrEmpty(name))
 | 
			
		||||
                    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;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// Create a derived type like PdfTextField or PdfCheckBox if possible.
 | 
			
		||||
            /// If the actual cannot be guessed by PDFsharp the function returns an instance
 | 
			
		||||
            /// of PdfGenericField.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            PdfAcroField CreateAcroField(PdfDictionary dict)
 | 
			
		||||
            {
 | 
			
		||||
                string ft = dict.Elements.GetName(Keys.FT);
 | 
			
		||||
                PdfAcroFieldFlags flags = (PdfAcroFieldFlags)dict.Elements.GetInteger(Keys.Ff);
 | 
			
		||||
                switch (ft)
 | 
			
		||||
                {
 | 
			
		||||
                    case "/Btn":
 | 
			
		||||
                        if ((flags & PdfAcroFieldFlags.Pushbutton) != 0)
 | 
			
		||||
                            return new PdfPushButtonField(dict);
 | 
			
		||||
 | 
			
		||||
                        if ((flags & PdfAcroFieldFlags.Radio) != 0)
 | 
			
		||||
                            return new PdfRadioButtonField(dict);
 | 
			
		||||
 | 
			
		||||
                        return new PdfCheckBoxField(dict);
 | 
			
		||||
 | 
			
		||||
                    case "/Tx":
 | 
			
		||||
                        return new PdfTextField(dict);
 | 
			
		||||
 | 
			
		||||
                    case "/Ch":
 | 
			
		||||
                        if ((flags & PdfAcroFieldFlags.Combo) != 0)
 | 
			
		||||
                            return new PdfComboBoxField(dict);
 | 
			
		||||
                        else
 | 
			
		||||
                            return new PdfListBoxField(dict);
 | 
			
		||||
 | 
			
		||||
                    case "/Sig":
 | 
			
		||||
                        return new PdfSignatureField(dict);
 | 
			
		||||
 | 
			
		||||
                    default:
 | 
			
		||||
                        return new PdfGenericField(dict);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Predefined keys of this dictionary. 
 | 
			
		||||
        /// The description comes from PDF 1.4 Reference.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public class Keys : KeysBase
 | 
			
		||||
        {
 | 
			
		||||
            // ReSharper disable InconsistentNaming
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Required for terminal fields; inheritable) The type of field that this dictionary
 | 
			
		||||
            /// describes:
 | 
			
		||||
            ///   Btn           Button
 | 
			
		||||
            ///   Tx            Text
 | 
			
		||||
            ///   Ch            Choice
 | 
			
		||||
            ///   Sig (PDF 1.3) Signature
 | 
			
		||||
            /// Note: This entry may be present in a nonterminal field (one whose descendants
 | 
			
		||||
            /// are themselves fields) in order to provide an inheritable FT value. However, a
 | 
			
		||||
            /// nonterminal field does not logically have a type of its own; it is merely a container
 | 
			
		||||
            /// for inheritable attributes that are intended for descendant terminal fields of
 | 
			
		||||
            /// any type.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo(KeyType.Name | KeyType.Required)]
 | 
			
		||||
            public const string FT = "/FT";
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Required if this field is the child of another in the field hierarchy; absent otherwise)
 | 
			
		||||
            /// The field that is the immediate parent of this one (the field, if any, whose Kids array
 | 
			
		||||
            /// includes this field). A field can have at most one parent; that is, it can be included
 | 
			
		||||
            /// in the Kids array of at most one other field.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo(KeyType.Dictionary)]
 | 
			
		||||
            public const string Parent = "/Parent";
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Optional) An array of indirect references to the immediate children of this field.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo(KeyType.Array | KeyType.Optional, typeof(PdfAcroFieldCollection))]
 | 
			
		||||
            public const string Kids = "/Kids";
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Optional) The partial field name.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo(KeyType.TextString | KeyType.Optional)]
 | 
			
		||||
            public const string T = "/T";
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Optional; PDF 1.3) An alternate field name, to be used in place of the actual
 | 
			
		||||
            /// field name wherever the field must be identified in the user interface (such as
 | 
			
		||||
            /// in error or status messages referring to the field). This text is also useful
 | 
			
		||||
            /// when extracting the document<6E>s contents in support of accessibility to disabled
 | 
			
		||||
            /// users or for other purposes.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo(KeyType.TextString | KeyType.Optional)]
 | 
			
		||||
            public const string TU = "/TU";
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Optional; PDF 1.3) The mapping name to be used when exporting interactive form field 
 | 
			
		||||
            /// data from the document.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo(KeyType.TextString | KeyType.Optional)]
 | 
			
		||||
            public const string TM = "/TM";
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Optional; inheritable) A set of flags specifying various characteristics of the field.
 | 
			
		||||
            /// Default value: 0.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo(KeyType.Integer | KeyType.Optional)]
 | 
			
		||||
            public const string Ff = "/Ff";
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Optional; inheritable) The field<6C>s value, whose format varies depending on
 | 
			
		||||
            /// the field type; see the descriptions of individual field types for further information.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo(KeyType.Various | KeyType.Optional)]
 | 
			
		||||
            public const string V = "/V";
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Optional; inheritable) The default value to which the field reverts when a
 | 
			
		||||
            /// reset-form action is executed. The format of this value is the same as that of V.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo(KeyType.Various | KeyType.Optional)]
 | 
			
		||||
            public const string DV = "/DV";
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Optional; PDF 1.2) An additional-actions dictionary defining the field<6C>s behavior
 | 
			
		||||
            /// in response to various trigger events. This entry has exactly the same meaning as
 | 
			
		||||
            /// the AA entry in an annotation dictionary.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo(KeyType.Dictionary | KeyType.Optional)]
 | 
			
		||||
            public const string AA = "/AA";
 | 
			
		||||
 | 
			
		||||
            // ----- Additional entries to all fields containing variable text --------------------------
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Required; inheritable) A resource dictionary containing default resources
 | 
			
		||||
            /// (such as fonts, patterns, or color spaces) to be used by the appearance stream.
 | 
			
		||||
            /// At a minimum, this dictionary must contain a Font entry specifying the resource
 | 
			
		||||
            /// name and font dictionary of the default font for displaying the field<6C>s text.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo(KeyType.Dictionary | KeyType.Required)]
 | 
			
		||||
            public const string DR = "/DR";
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Required; inheritable) The default appearance string, containing a sequence of
 | 
			
		||||
            /// valid page-content graphics or text state operators defining such properties as
 | 
			
		||||
            /// the field<6C>s text size and color.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo(KeyType.String | KeyType.Required)]
 | 
			
		||||
            public const string DA = "/DA";
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Optional; inheritable) A code specifying the form of quadding (justification)
 | 
			
		||||
            /// to be used in displaying the text:
 | 
			
		||||
            ///   0 Left-justified
 | 
			
		||||
            ///   1 Centered
 | 
			
		||||
            ///   2 Right-justified
 | 
			
		||||
            /// Default value: 0 (left-justified).
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo(KeyType.Integer | KeyType.Optional)]
 | 
			
		||||
            public const string Q = "/Q";
 | 
			
		||||
 | 
			
		||||
            // ReSharper restore InconsistentNaming
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										151
									
								
								PrintPDF/PdfSharp/Pdf.AcroForms/PdfAcroForm.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										151
									
								
								PrintPDF/PdfSharp/Pdf.AcroForms/PdfAcroForm.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,151 @@
 | 
			
		||||
#region PDFsharp - A .NET library for processing PDF
 | 
			
		||||
//
 | 
			
		||||
// Authors:
 | 
			
		||||
//   Stefan Lange
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2005-2017 empira Software GmbH, Cologne Area (Germany)
 | 
			
		||||
//
 | 
			
		||||
// http://www.pdfsharp.com
 | 
			
		||||
// http://sourceforge.net/projects/pdfsharp
 | 
			
		||||
//
 | 
			
		||||
// Permission is hereby granted, free of charge, to any person obtaining a
 | 
			
		||||
// copy of this software and associated documentation files (the "Software"),
 | 
			
		||||
// to deal in the Software without restriction, including without limitation
 | 
			
		||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
 | 
			
		||||
// and/or sell copies of the Software, and to permit persons to whom the
 | 
			
		||||
// Software is furnished to do so, subject to the following conditions:
 | 
			
		||||
//
 | 
			
		||||
// The above copyright notice and this permission notice shall be included
 | 
			
		||||
// in all copies or substantial portions of the Software.
 | 
			
		||||
//
 | 
			
		||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 | 
			
		||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 | 
			
		||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 | 
			
		||||
// DEALINGS IN THE SOFTWARE.
 | 
			
		||||
#endregion
 | 
			
		||||
 | 
			
		||||
namespace PdfSharp.Pdf.AcroForms
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Represents an interactive form (or AcroForm), a collection of fields for
 | 
			
		||||
    /// gathering information interactively from the user.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public sealed class PdfAcroForm : PdfDictionary
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Initializes a new instance of AcroForm.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        internal PdfAcroForm(PdfDocument document)
 | 
			
		||||
            : base(document)
 | 
			
		||||
        {
 | 
			
		||||
            _document = document;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        internal PdfAcroForm(PdfDictionary dictionary)
 | 
			
		||||
            : base(dictionary)
 | 
			
		||||
        { }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the fields collection of this form.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public PdfAcroField.PdfAcroFieldCollection Fields
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                if (_fields == null)
 | 
			
		||||
                {
 | 
			
		||||
                    object o = Elements.GetValue(Keys.Fields, VCF.CreateIndirect);
 | 
			
		||||
                    _fields = (PdfAcroField.PdfAcroFieldCollection)o;
 | 
			
		||||
                }
 | 
			
		||||
                return _fields;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        PdfAcroField.PdfAcroFieldCollection _fields;
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Predefined keys of this dictionary. 
 | 
			
		||||
        /// The description comes from PDF 1.4 Reference.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public sealed class Keys : KeysBase
 | 
			
		||||
        {
 | 
			
		||||
            // ReSharper disable InconsistentNaming
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Required) An array of references to the document<6E>s root fields (those with
 | 
			
		||||
            /// no ancestors in the field hierarchy).
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo(KeyType.Array | KeyType.Required, typeof(PdfAcroField.PdfAcroFieldCollection))]
 | 
			
		||||
            public const string Fields = "/Fields";
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Optional) A flag specifying whether to construct appearance streams and
 | 
			
		||||
            /// appearance dictionaries for all widget annotations in the document.
 | 
			
		||||
            /// Default value: false.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo(KeyType.Boolean | KeyType.Optional)]
 | 
			
		||||
            public const string NeedAppearances = "/NeedAppearances";
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Optional; PDF 1.3) A set of flags specifying various document-level characteristics
 | 
			
		||||
            /// related to signature fields.
 | 
			
		||||
            /// Default value: 0.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo("1.3", KeyType.Integer | KeyType.Optional)]
 | 
			
		||||
            public const string SigFlags = "/SigFlags";
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Required if any fields in the document have additional-actions dictionaries
 | 
			
		||||
            /// containing a C entry; PDF 1.3) An array of indirect references to field dictionaries
 | 
			
		||||
            /// with calculation actions, defining the calculation order in which their values will 
 | 
			
		||||
            /// be recalculated when the value of any field changes.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo(KeyType.Array)]
 | 
			
		||||
            public const string CO = "/CO";
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Optional) A document-wide default value for the DR attribute of variable text fields.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo(KeyType.Dictionary | KeyType.Optional)]
 | 
			
		||||
            public const string DR = "/DR";
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Optional) A document-wide default value for the DA attribute of variable text fields.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo(KeyType.String | KeyType.Optional)]
 | 
			
		||||
            public const string DA = "/DA";
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Optional) A document-wide default value for the Q attribute of variable text fields.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo(KeyType.Integer | KeyType.Optional)]
 | 
			
		||||
            public const string Q = "/Q";
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// Gets the KeysMeta for these keys.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            internal static DictionaryMeta Meta
 | 
			
		||||
            {
 | 
			
		||||
                get
 | 
			
		||||
                {
 | 
			
		||||
                    if (s_meta == null)
 | 
			
		||||
                        s_meta = CreateMeta(typeof(Keys));
 | 
			
		||||
                    return s_meta;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            static DictionaryMeta s_meta;
 | 
			
		||||
 | 
			
		||||
            // ReSharper restore InconsistentNaming
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the KeysMeta of this dictionary type.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        internal override DictionaryMeta Meta
 | 
			
		||||
        {
 | 
			
		||||
            get { return Keys.Meta; }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										103
									
								
								PrintPDF/PdfSharp/Pdf.AcroForms/PdfButtonField.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										103
									
								
								PrintPDF/PdfSharp/Pdf.AcroForms/PdfButtonField.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,103 @@
 | 
			
		||||
#region PDFsharp - A .NET library for processing PDF
 | 
			
		||||
//
 | 
			
		||||
// Authors:
 | 
			
		||||
//   Stefan Lange
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2005-2017 empira Software GmbH, Cologne Area (Germany)
 | 
			
		||||
//
 | 
			
		||||
// http://www.pdfsharp.com
 | 
			
		||||
// http://sourceforge.net/projects/pdfsharp
 | 
			
		||||
//
 | 
			
		||||
// Permission is hereby granted, free of charge, to any person obtaining a
 | 
			
		||||
// copy of this software and associated documentation files (the "Software"),
 | 
			
		||||
// to deal in the Software without restriction, including without limitation
 | 
			
		||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
 | 
			
		||||
// and/or sell copies of the Software, and to permit persons to whom the
 | 
			
		||||
// Software is furnished to do so, subject to the following conditions:
 | 
			
		||||
//
 | 
			
		||||
// The above copyright notice and this permission notice shall be included
 | 
			
		||||
// in all copies or substantial portions of the Software.
 | 
			
		||||
//
 | 
			
		||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 | 
			
		||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 | 
			
		||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 | 
			
		||||
// DEALINGS IN THE SOFTWARE.
 | 
			
		||||
#endregion
 | 
			
		||||
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Diagnostics;
 | 
			
		||||
using PdfSharp.Pdf.Annotations;
 | 
			
		||||
 | 
			
		||||
namespace PdfSharp.Pdf.AcroForms
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Represents the base class for all button fields.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public abstract class PdfButtonField : PdfAcroField
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Initializes a new instance of the <see cref="PdfButtonField"/> class.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        protected PdfButtonField(PdfDocument document)
 | 
			
		||||
            : base(document)
 | 
			
		||||
        { }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Initializes a new instance of the <see cref="PdfButtonField"/> class.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        protected PdfButtonField(PdfDictionary dict)
 | 
			
		||||
            : base(dict)
 | 
			
		||||
        { }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the name which represents the opposite of /Off.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        protected string GetNonOffValue()
 | 
			
		||||
        {
 | 
			
		||||
            // Try to get the information from the appearance dictionaray.
 | 
			
		||||
            // Just return the first key that is not /Off.
 | 
			
		||||
            // I'm not sure what is the right solution to get this value.
 | 
			
		||||
            PdfDictionary ap = Elements[PdfAnnotation.Keys.AP] as PdfDictionary;
 | 
			
		||||
            if (ap != null)
 | 
			
		||||
            {
 | 
			
		||||
                PdfDictionary n = ap.Elements["/N"] as PdfDictionary;
 | 
			
		||||
                if (n != null)
 | 
			
		||||
                {
 | 
			
		||||
                    foreach (string name in n.Elements.Keys)
 | 
			
		||||
                        if (name != "/Off")
 | 
			
		||||
                            return name;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        internal override void GetDescendantNames(ref List<string> names, string partialName)
 | 
			
		||||
        {
 | 
			
		||||
            string t = Elements.GetString(PdfAcroField.Keys.T);
 | 
			
		||||
            // HACK: ??? 
 | 
			
		||||
            if (t == "")
 | 
			
		||||
                t = "???";
 | 
			
		||||
            Debug.Assert(t != "");
 | 
			
		||||
            if (t.Length > 0)
 | 
			
		||||
            {
 | 
			
		||||
                if (!String.IsNullOrEmpty(partialName))
 | 
			
		||||
                    names.Add(partialName + "." + t);
 | 
			
		||||
                else
 | 
			
		||||
                    names.Add(t);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Predefined keys of this dictionary. 
 | 
			
		||||
        /// The description comes from PDF 1.4 Reference.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public new class Keys : PdfAcroField.Keys
 | 
			
		||||
        {
 | 
			
		||||
            // Pushbuttons have no additional entries.
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										401
									
								
								PrintPDF/PdfSharp/Pdf.AcroForms/PdfCheckBoxField.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										401
									
								
								PrintPDF/PdfSharp/Pdf.AcroForms/PdfCheckBoxField.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,401 @@
 | 
			
		||||
#region PDFsharp - A .NET library for processing PDF
 | 
			
		||||
//
 | 
			
		||||
// Authors:
 | 
			
		||||
//   Stefan Lange
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2005-2017 empira Software GmbH, Cologne Area (Germany)
 | 
			
		||||
//
 | 
			
		||||
// http://www.pdfsharp.com
 | 
			
		||||
// http://sourceforge.net/projects/pdfsharp
 | 
			
		||||
//
 | 
			
		||||
// Permission is hereby granted, free of charge, to any person obtaining a
 | 
			
		||||
// copy of this software and associated documentation files (the "Software"),
 | 
			
		||||
// to deal in the Software without restriction, including without limitation
 | 
			
		||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
 | 
			
		||||
// and/or sell copies of the Software, and to permit persons to whom the
 | 
			
		||||
// Software is furnished to do so, subject to the following conditions:
 | 
			
		||||
//
 | 
			
		||||
// The above copyright notice and this permission notice shall be included
 | 
			
		||||
// in all copies or substantial portions of the Software.
 | 
			
		||||
//
 | 
			
		||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 | 
			
		||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 | 
			
		||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 | 
			
		||||
// DEALINGS IN THE SOFTWARE.
 | 
			
		||||
#endregion
 | 
			
		||||
 | 
			
		||||
using PdfSharp.Pdf.Annotations;
 | 
			
		||||
using PdfSharp.Pdf.Advanced;
 | 
			
		||||
 | 
			
		||||
namespace PdfSharp.Pdf.AcroForms
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Represents the check box field.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public sealed class PdfCheckBoxField : PdfButtonField
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Initializes a new instance of PdfCheckBoxField.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        internal PdfCheckBoxField(PdfDocument document)
 | 
			
		||||
            : base(document)
 | 
			
		||||
        {
 | 
			
		||||
            _document = document;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        internal PdfCheckBoxField(PdfDictionary dict)
 | 
			
		||||
            : base(dict)
 | 
			
		||||
        { }
 | 
			
		||||
 | 
			
		||||
#if true_
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Indicates whether the field is checked.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public bool Checked  //R080317 // TODO
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                if (!HasKids)
 | 
			
		||||
                {
 | 
			
		||||
                    string value = Elements.GetString(Keys.V);
 | 
			
		||||
                    //return !String.IsNullOrEmpty(value) && value != UncheckedValue;
 | 
			
		||||
                    return !String.IsNullOrEmpty(value) && value == CheckedName;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (Fields.Elements.Items.Length == 2)
 | 
			
		||||
                {
 | 
			
		||||
                    string value = ((PdfDictionary)(((PdfReference)(Fields.Elements.Items[0])).Value)).Elements.GetString(Keys.V);
 | 
			
		||||
                    //bool bReturn = value.Length != 0 && value != UncheckedValue; //R081114 (3Std.!!) auch auf Nein pr<70>fen; //TODO woher kommt der Wert?
 | 
			
		||||
                    bool bReturn = value.Length != 0 && value == CheckedName;
 | 
			
		||||
                    return bReturn;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                // NYI: Return false in any other case. 
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                if (!HasKids)
 | 
			
		||||
                {
 | 
			
		||||
                    //string name = value ? GetNonOffValue() : "/Off";
 | 
			
		||||
                    string name = value ? CheckedName : UncheckedName;
 | 
			
		||||
                    Elements.SetName(Keys.V, name);
 | 
			
		||||
                    Elements.SetName(PdfAnnotation.Keys.AS, name);
 | 
			
		||||
                }
 | 
			
		||||
                else
 | 
			
		||||
                {
 | 
			
		||||
                    // Here we have to handle fields that exist twice with the same name.
 | 
			
		||||
                    // Checked must be set for both fields, using /Off for one field and skipping /Off for the other,
 | 
			
		||||
                    // to have only one field with a check mark.
 | 
			
		||||
                    // Finding this took me two working days.
 | 
			
		||||
                    if (Fields.Elements.Items.Length == 2)
 | 
			
		||||
                    {
 | 
			
		||||
                        if (value)
 | 
			
		||||
                        {
 | 
			
		||||
                            //Element 0 behandeln -> auf checked setzen
 | 
			
		||||
                            string name1 = "";
 | 
			
		||||
                            PdfDictionary o = ((PdfDictionary)(((PdfReference)(Fields.Elements.Items[0])).Value)).Elements["/AP"] as PdfDictionary;
 | 
			
		||||
                            if (o != null)
 | 
			
		||||
                            {
 | 
			
		||||
                                PdfDictionary n = o.Elements["/N"] as PdfDictionary;
 | 
			
		||||
                                if (n != null)
 | 
			
		||||
                                {
 | 
			
		||||
                                    foreach (string name in n.Elements.Keys)
 | 
			
		||||
                                    {
 | 
			
		||||
                                        //if (name != UncheckedValue)
 | 
			
		||||
                                        if (name == CheckedName)
 | 
			
		||||
                                        {
 | 
			
		||||
                                            name1 = name;
 | 
			
		||||
                                            break;
 | 
			
		||||
                                        }
 | 
			
		||||
                                    }
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                            if (name1.Length != 0)
 | 
			
		||||
                            {
 | 
			
		||||
                                ((PdfDictionary)(((PdfReference)(Fields.Elements.Items[0])).Value)).Elements.SetName(Keys.V, name1);
 | 
			
		||||
                                ((PdfDictionary)(((PdfReference)(Fields.Elements.Items[0])).Value)).Elements.SetName(PdfAnnotation.Keys.AS, name1);
 | 
			
		||||
                            }
 | 
			
		||||
 | 
			
		||||
                            //Element 1 behandeln -> auf unchecked setzen
 | 
			
		||||
                            o = ((PdfDictionary)(((PdfReference)(Fields.Elements.Items[1])).Value)).Elements["/AP"] as PdfDictionary;
 | 
			
		||||
                            if (o != null)
 | 
			
		||||
                            {
 | 
			
		||||
                                PdfDictionary n = o.Elements["/N"] as PdfDictionary;
 | 
			
		||||
                                if (n != null)
 | 
			
		||||
                                {
 | 
			
		||||
                                    foreach (string name in n.Elements.Keys)
 | 
			
		||||
                                    {
 | 
			
		||||
                                        if (name == UncheckedName)
 | 
			
		||||
                                        {
 | 
			
		||||
                                            name1 = name;
 | 
			
		||||
                                            break;
 | 
			
		||||
                                        }
 | 
			
		||||
                                    }
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                            if (!String.IsNullOrEmpty(name1))
 | 
			
		||||
                            {
 | 
			
		||||
                                ((PdfDictionary)(((PdfReference)(Fields.Elements.Items[1])).Value)).Elements.SetName(Keys.V, name1);
 | 
			
		||||
                                ((PdfDictionary)(((PdfReference)(Fields.Elements.Items[1])).Value)).Elements.SetName(PdfAnnotation.Keys.AS, name1);
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                        else
 | 
			
		||||
                        {
 | 
			
		||||
                            //Element 0 behandeln -> auf unchecked setzen
 | 
			
		||||
                            string name1 = "";
 | 
			
		||||
                            PdfDictionary o = ((PdfDictionary)(((PdfReference)(Fields.Elements.Items[1])).Value)).Elements["/AP"] as PdfDictionary;
 | 
			
		||||
                            if (o != null)
 | 
			
		||||
                            {
 | 
			
		||||
                                PdfDictionary n = o.Elements["/N"] as PdfDictionary;
 | 
			
		||||
                                if (n != null)
 | 
			
		||||
                                {
 | 
			
		||||
                                    foreach (string name in n.Elements.Keys)
 | 
			
		||||
                                    {
 | 
			
		||||
                                        //if (name != UncheckedValue)
 | 
			
		||||
                                        if (name == CheckedName)
 | 
			
		||||
                                        {
 | 
			
		||||
                                            name1 = name;
 | 
			
		||||
                                            break;
 | 
			
		||||
                                        }
 | 
			
		||||
                                    }
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                            if (name1.Length != 0)
 | 
			
		||||
                            {
 | 
			
		||||
                                ((PdfDictionary)(((PdfReference)(Fields.Elements.Items[1])).Value)).Elements.SetName(Keys.V, name1);
 | 
			
		||||
                                ((PdfDictionary)(((PdfReference)(Fields.Elements.Items[1])).Value)).Elements.SetName(PdfAnnotation.Keys.AS, name1);
 | 
			
		||||
                            }
 | 
			
		||||
 | 
			
		||||
                            //Element 1 behandeln -> auf checked setzen
 | 
			
		||||
                            o = ((PdfDictionary)(((PdfReference)(Fields.Elements.Items[0])).Value)).Elements["/AP"] as PdfDictionary;
 | 
			
		||||
                            if (o != null)
 | 
			
		||||
                            {
 | 
			
		||||
                                PdfDictionary n = o.Elements["/N"] as PdfDictionary;
 | 
			
		||||
                                if (n != null)
 | 
			
		||||
                                {
 | 
			
		||||
                                    foreach (string name in n.Elements.Keys)
 | 
			
		||||
                                    {
 | 
			
		||||
                                        if (name == UncheckedName)
 | 
			
		||||
                                        {
 | 
			
		||||
                                            name1 = name;
 | 
			
		||||
                                            break;
 | 
			
		||||
                                        }
 | 
			
		||||
                                    }
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                            if (name1.Length != 0)
 | 
			
		||||
                            {
 | 
			
		||||
                                ((PdfDictionary)(((PdfReference)(Fields.Elements.Items[0])).Value)).Elements.SetName(Keys.V, name1);
 | 
			
		||||
                                ((PdfDictionary)(((PdfReference)(Fields.Elements.Items[0])).Value)).Elements.SetName(PdfAnnotation.Keys.AS, name1);
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
#else
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Indicates whether the field is checked.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public bool Checked
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                if (!HasKids) //R080317
 | 
			
		||||
                {
 | 
			
		||||
                    string value = Elements.GetString(Keys.V);
 | 
			
		||||
                    return value.Length != 0 && value != "/Off";
 | 
			
		||||
                }
 | 
			
		||||
                else //R080317
 | 
			
		||||
                {
 | 
			
		||||
                    if (Fields.Elements.Items.Length == 2)
 | 
			
		||||
                    {
 | 
			
		||||
                        string value = ((PdfDictionary)(((PdfReference)(Fields.Elements.Items[0])).Value)).Elements.GetString(Keys.V);
 | 
			
		||||
                        bool bReturn = value.Length != 0 && value != "/Off" && value != "/Nein"; //R081114 (3Std.!!) auch auf Nein pr<70>fen; //TODO woher kommt der Wert?
 | 
			
		||||
                        return bReturn;
 | 
			
		||||
                    }
 | 
			
		||||
                    else
 | 
			
		||||
                        return false;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                if (!HasKids)
 | 
			
		||||
                {
 | 
			
		||||
                    string name = value ? GetNonOffValue() : "/Off";
 | 
			
		||||
                    Elements.SetName(Keys.V, name);
 | 
			
		||||
                    Elements.SetName(PdfAnnotation.Keys.AS, name);
 | 
			
		||||
                }
 | 
			
		||||
                else
 | 
			
		||||
                {
 | 
			
		||||
                    // Here we have to handle fields that exist twice with the same name.
 | 
			
		||||
                    // Checked must be set for both fields, using /Off for one field and skipping /Off for the other,
 | 
			
		||||
                    // to have only one field with a check mark.
 | 
			
		||||
                    // Finding this took me two working days.
 | 
			
		||||
                    if (Fields.Elements.Items.Length == 2)
 | 
			
		||||
                    {
 | 
			
		||||
                        if (value)
 | 
			
		||||
                        {
 | 
			
		||||
                            //Element 0 behandeln -> auf checked setzen
 | 
			
		||||
                            string name1 = "";
 | 
			
		||||
                            PdfDictionary o = ((PdfDictionary)(((PdfReference)(Fields.Elements.Items[0])).Value)).Elements["/AP"] as PdfDictionary;
 | 
			
		||||
                            if (o != null)
 | 
			
		||||
                            {
 | 
			
		||||
                                PdfDictionary n = o.Elements["/N"] as PdfDictionary;
 | 
			
		||||
                                if (n != null)
 | 
			
		||||
                                {
 | 
			
		||||
                                    foreach (string name in n.Elements.Keys)
 | 
			
		||||
                                    {
 | 
			
		||||
                                        if (name != "/Off")
 | 
			
		||||
                                        {
 | 
			
		||||
                                            name1 = name;
 | 
			
		||||
                                            break;
 | 
			
		||||
                                        }
 | 
			
		||||
                                    }
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                            if (name1.Length != 0)
 | 
			
		||||
                            {
 | 
			
		||||
                                ((PdfDictionary)(((PdfReference)(Fields.Elements.Items[0])).Value)).Elements.SetName(Keys.V, name1);
 | 
			
		||||
                                ((PdfDictionary)(((PdfReference)(Fields.Elements.Items[0])).Value)).Elements.SetName(PdfAnnotation.Keys.AS, name1);
 | 
			
		||||
                            }
 | 
			
		||||
 | 
			
		||||
                            //Element 1 behandeln -> auf unchecked setzen
 | 
			
		||||
                            o = ((PdfDictionary)(((PdfReference)(Fields.Elements.Items[1])).Value)).Elements["/AP"] as PdfDictionary;
 | 
			
		||||
                            if (o != null)
 | 
			
		||||
                            {
 | 
			
		||||
                                PdfDictionary n = o.Elements["/N"] as PdfDictionary;
 | 
			
		||||
                                if (n != null)
 | 
			
		||||
                                {
 | 
			
		||||
                                    foreach (string name in n.Elements.Keys)
 | 
			
		||||
                                    {
 | 
			
		||||
                                        if (name == "/Off")
 | 
			
		||||
                                        {
 | 
			
		||||
                                            name1 = name;
 | 
			
		||||
                                            break;
 | 
			
		||||
                                        }
 | 
			
		||||
                                    }
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                            if (name1.Length != 0)
 | 
			
		||||
                            {
 | 
			
		||||
                                ((PdfDictionary)(((PdfReference)(Fields.Elements.Items[1])).Value)).Elements.SetName(Keys.V, name1);
 | 
			
		||||
                                ((PdfDictionary)(((PdfReference)(Fields.Elements.Items[1])).Value)).Elements.SetName(PdfAnnotation.Keys.AS, name1);
 | 
			
		||||
                            }
 | 
			
		||||
 | 
			
		||||
                        }
 | 
			
		||||
                        else
 | 
			
		||||
                        {
 | 
			
		||||
                            //Element 0 behandeln -> auf unchecked setzen
 | 
			
		||||
                            string name1 = "";
 | 
			
		||||
                            PdfDictionary o = ((PdfDictionary)(((PdfReference)(Fields.Elements.Items[1])).Value)).Elements["/AP"] as PdfDictionary;
 | 
			
		||||
                            if (o != null)
 | 
			
		||||
                            {
 | 
			
		||||
                                PdfDictionary n = o.Elements["/N"] as PdfDictionary;
 | 
			
		||||
                                if (n != null)
 | 
			
		||||
                                {
 | 
			
		||||
                                    foreach (string name in n.Elements.Keys)
 | 
			
		||||
                                    {
 | 
			
		||||
                                        if (name != "/Off")
 | 
			
		||||
                                        {
 | 
			
		||||
                                            name1 = name;
 | 
			
		||||
                                            break;
 | 
			
		||||
                                        }
 | 
			
		||||
                                    }
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                            if (name1.Length != 0)
 | 
			
		||||
                            {
 | 
			
		||||
                                ((PdfDictionary)(((PdfReference)(Fields.Elements.Items[1])).Value)).Elements.SetName(Keys.V, name1);
 | 
			
		||||
                                ((PdfDictionary)(((PdfReference)(Fields.Elements.Items[1])).Value)).Elements.SetName(PdfAnnotation.Keys.AS, name1);
 | 
			
		||||
                            }
 | 
			
		||||
 | 
			
		||||
                            //Element 1 behandeln -> auf checked setzen
 | 
			
		||||
                            o = ((PdfDictionary)(((PdfReference)(Fields.Elements.Items[0])).Value)).Elements["/AP"] as PdfDictionary;
 | 
			
		||||
                            if (o != null)
 | 
			
		||||
                            {
 | 
			
		||||
                                PdfDictionary n = o.Elements["/N"] as PdfDictionary;
 | 
			
		||||
                                if (n != null)
 | 
			
		||||
                                {
 | 
			
		||||
                                    foreach (string name in n.Elements.Keys)
 | 
			
		||||
                                    {
 | 
			
		||||
                                        if (name == "/Off")
 | 
			
		||||
                                        {
 | 
			
		||||
                                            name1 = name;
 | 
			
		||||
                                            break;
 | 
			
		||||
                                        }
 | 
			
		||||
                                    }
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                            if (name1.Length != 0)
 | 
			
		||||
                            {
 | 
			
		||||
                                ((PdfDictionary)(((PdfReference)(Fields.Elements.Items[0])).Value)).Elements.SetName(Keys.V, name1);
 | 
			
		||||
                                ((PdfDictionary)(((PdfReference)(Fields.Elements.Items[0])).Value)).Elements.SetName(PdfAnnotation.Keys.AS, name1);
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the name of the dictionary that represents the Checked state.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// The default value is "/Yes".
 | 
			
		||||
        public string CheckedName
 | 
			
		||||
        {
 | 
			
		||||
            get { return _checkedName; }
 | 
			
		||||
            set { _checkedName = value; }
 | 
			
		||||
        }
 | 
			
		||||
        string _checkedName = "/Yes";
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the name of the dictionary that represents the Unchecked state.
 | 
			
		||||
        /// The default value is "/Off".
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string UncheckedName
 | 
			
		||||
        {
 | 
			
		||||
            get { return _uncheckedName; }
 | 
			
		||||
            set { _uncheckedName = value; }
 | 
			
		||||
        }
 | 
			
		||||
        string _uncheckedName = "/Off";
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Predefined keys of this dictionary. 
 | 
			
		||||
        /// The description comes from PDF 1.4 Reference.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public new class Keys : PdfButtonField.Keys
 | 
			
		||||
        {
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Optional; inheritable; PDF 1.4) A text string to be used in place of the V entry for the
 | 
			
		||||
            /// value of the field.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo(KeyType.TextString | KeyType.Optional)]
 | 
			
		||||
            public const string Opt = "/Opt";
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// Gets the KeysMeta for these keys.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            internal static DictionaryMeta Meta
 | 
			
		||||
            {
 | 
			
		||||
                get { return _meta ?? (_meta = CreateMeta(typeof(Keys))); }
 | 
			
		||||
            }
 | 
			
		||||
            static DictionaryMeta _meta;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the KeysMeta of this dictionary type.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        internal override DictionaryMeta Meta
 | 
			
		||||
        {
 | 
			
		||||
            get { return Keys.Meta; }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										181
									
								
								PrintPDF/PdfSharp/Pdf.AcroForms/PdfChoiceField.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										181
									
								
								PrintPDF/PdfSharp/Pdf.AcroForms/PdfChoiceField.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,181 @@
 | 
			
		||||
#region PDFsharp - A .NET library for processing PDF
 | 
			
		||||
//
 | 
			
		||||
// Authors:
 | 
			
		||||
//   Stefan Lange
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2005-2017 empira Software GmbH, Cologne Area (Germany)
 | 
			
		||||
//
 | 
			
		||||
// http://www.pdfsharp.com
 | 
			
		||||
// http://sourceforge.net/projects/pdfsharp
 | 
			
		||||
//
 | 
			
		||||
// Permission is hereby granted, free of charge, to any person obtaining a
 | 
			
		||||
// copy of this software and associated documentation files (the "Software"),
 | 
			
		||||
// to deal in the Software without restriction, including without limitation
 | 
			
		||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
 | 
			
		||||
// and/or sell copies of the Software, and to permit persons to whom the
 | 
			
		||||
// Software is furnished to do so, subject to the following conditions:
 | 
			
		||||
//
 | 
			
		||||
// The above copyright notice and this permission notice shall be included
 | 
			
		||||
// in all copies or substantial portions of the Software.
 | 
			
		||||
//
 | 
			
		||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 | 
			
		||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 | 
			
		||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 | 
			
		||||
// DEALINGS IN THE SOFTWARE.
 | 
			
		||||
#endregion
 | 
			
		||||
 | 
			
		||||
using System;
 | 
			
		||||
using System.Diagnostics;
 | 
			
		||||
 | 
			
		||||
namespace PdfSharp.Pdf.AcroForms
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Represents the base class for all choice field dictionaries.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public abstract class PdfChoiceField : PdfAcroField
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Initializes a new instance of the <see cref="PdfChoiceField"/> class.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        protected PdfChoiceField(PdfDocument document)
 | 
			
		||||
            : base(document)
 | 
			
		||||
        { }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Initializes a new instance of the <see cref="PdfChoiceField"/> class.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        protected PdfChoiceField(PdfDictionary dict)
 | 
			
		||||
            : base(dict)
 | 
			
		||||
        { }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the index of the specified string in the /Opt array or -1, if no such string exists.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        protected int IndexInOptArray(string value)
 | 
			
		||||
        {
 | 
			
		||||
            PdfArray opt = Elements.GetArray(Keys.Opt);
 | 
			
		||||
 | 
			
		||||
#if DEBUG  // Check with //R080317 implemention
 | 
			
		||||
            PdfArray opt2 = null;
 | 
			
		||||
            if (Elements[Keys.Opt] is PdfArray)
 | 
			
		||||
                opt2 = Elements[Keys.Opt] as PdfArray;
 | 
			
		||||
            else if (Elements[Keys.Opt] is Advanced.PdfReference)
 | 
			
		||||
            {
 | 
			
		||||
                //falls das Array nicht direkt am Element h<>ngt, 
 | 
			
		||||
                //das Array aus dem referenzierten Element holen
 | 
			
		||||
                opt2 = ((Advanced.PdfReference)Elements[Keys.Opt]).Value as PdfArray;
 | 
			
		||||
            }
 | 
			
		||||
            Debug.Assert(ReferenceEquals(opt, opt2));
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
            if (opt != null)
 | 
			
		||||
            {
 | 
			
		||||
                int count = opt.Elements.Count;
 | 
			
		||||
                for (int idx = 0; idx < count; idx++)
 | 
			
		||||
                {
 | 
			
		||||
                    PdfItem item = opt.Elements[idx];
 | 
			
		||||
                    if (item is PdfString)
 | 
			
		||||
                    {
 | 
			
		||||
                        if (item.ToString() == value)
 | 
			
		||||
                            return idx;
 | 
			
		||||
                    }
 | 
			
		||||
                    else if (item is PdfArray)
 | 
			
		||||
                    {
 | 
			
		||||
                        PdfArray array = (PdfArray)item;
 | 
			
		||||
                        if (array.Elements.Count != 0)
 | 
			
		||||
                        {
 | 
			
		||||
                            if (array.Elements[0].ToString() == value)
 | 
			
		||||
                                return idx;
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            return -1;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the value from the index in the /Opt array.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        protected string ValueInOptArray(int index)
 | 
			
		||||
        {
 | 
			
		||||
            PdfArray opt = Elements.GetArray(Keys.Opt);
 | 
			
		||||
            if (opt != null)
 | 
			
		||||
            {
 | 
			
		||||
                int count = opt.Elements.Count;
 | 
			
		||||
                if (index < 0 || index >= count)
 | 
			
		||||
                    throw new ArgumentOutOfRangeException("index");
 | 
			
		||||
 | 
			
		||||
                PdfItem item = opt.Elements[index];
 | 
			
		||||
                if (item is PdfString)
 | 
			
		||||
                    return item.ToString();
 | 
			
		||||
 | 
			
		||||
                if (item is PdfArray)
 | 
			
		||||
                {
 | 
			
		||||
                    PdfArray array = (PdfArray)item;
 | 
			
		||||
                    if (array.Elements.Count != 0)
 | 
			
		||||
                        return array.Elements[0].ToString();
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            return "";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Predefined keys of this dictionary. 
 | 
			
		||||
        /// The description comes from PDF 1.4 Reference.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public new class Keys : PdfAcroField.Keys
 | 
			
		||||
        {
 | 
			
		||||
            // ReSharper disable InconsistentNaming
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Required; inheritable) An array of options to be presented to the user. Each element of
 | 
			
		||||
            /// the array is either a text string representing one of the available options or a two-element
 | 
			
		||||
            /// array consisting of a text string together with a default appearance string for constructing
 | 
			
		||||
            /// the item<65>s appearance dynamically at viewing time.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo(KeyType.Array | KeyType.Optional)]
 | 
			
		||||
            public const string Opt = "/Opt";
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Optional; inheritable) For scrollable list boxes, the top index (the index in the Opt array
 | 
			
		||||
            /// of the first option visible in the list).
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo(KeyType.Integer | KeyType.Optional)]
 | 
			
		||||
            public const string TI = "/TI";
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Sometimes required, otherwise optional; inheritable; PDF 1.4) For choice fields that allow
 | 
			
		||||
            /// multiple selection (MultiSelect flag set), an array of integers, sorted in ascending order,
 | 
			
		||||
            /// representing the zero-based indices in the Opt array of the currently selected option
 | 
			
		||||
            /// items. This entry is required when two or more elements in the Opt array have different
 | 
			
		||||
            /// names but the same export value, or when the value of the choice field is an array; in
 | 
			
		||||
            /// other cases, it is permitted but not required. If the items identified by this entry differ
 | 
			
		||||
            /// from those in the V entry of the field dictionary (see below), the V entry takes precedence.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo(KeyType.Array | KeyType.Optional)]
 | 
			
		||||
            public const string I = "/I";
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// Gets the KeysMeta for these keys.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            internal static DictionaryMeta Meta
 | 
			
		||||
            {
 | 
			
		||||
                get { return _meta ?? (_meta = CreateMeta(typeof(Keys))); }
 | 
			
		||||
            }
 | 
			
		||||
            static DictionaryMeta _meta;
 | 
			
		||||
 | 
			
		||||
            // ReSharper restore InconsistentNaming
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the KeysMeta of this dictionary type.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        internal override DictionaryMeta Meta
 | 
			
		||||
        {
 | 
			
		||||
            get { return Keys.Meta; }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										132
									
								
								PrintPDF/PdfSharp/Pdf.AcroForms/PdfComboBoxField.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										132
									
								
								PrintPDF/PdfSharp/Pdf.AcroForms/PdfComboBoxField.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,132 @@
 | 
			
		||||
#region PDFsharp - A .NET library for processing PDF
 | 
			
		||||
//
 | 
			
		||||
// Authors:
 | 
			
		||||
//   Stefan Lange
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2005-2017 empira Software GmbH, Cologne Area (Germany)
 | 
			
		||||
//
 | 
			
		||||
// http://www.pdfsharp.com
 | 
			
		||||
// http://sourceforge.net/projects/pdfsharp
 | 
			
		||||
//
 | 
			
		||||
// Permission is hereby granted, free of charge, to any person obtaining a
 | 
			
		||||
// copy of this software and associated documentation files (the "Software"),
 | 
			
		||||
// to deal in the Software without restriction, including without limitation
 | 
			
		||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
 | 
			
		||||
// and/or sell copies of the Software, and to permit persons to whom the
 | 
			
		||||
// Software is furnished to do so, subject to the following conditions:
 | 
			
		||||
//
 | 
			
		||||
// The above copyright notice and this permission notice shall be included
 | 
			
		||||
// in all copies or substantial portions of the Software.
 | 
			
		||||
//
 | 
			
		||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 | 
			
		||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 | 
			
		||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 | 
			
		||||
// DEALINGS IN THE SOFTWARE.
 | 
			
		||||
#endregion
 | 
			
		||||
 | 
			
		||||
using System;
 | 
			
		||||
 | 
			
		||||
namespace PdfSharp.Pdf.AcroForms
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Represents the combo box field.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public sealed class PdfComboBoxField : PdfChoiceField
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Initializes a new instance of PdfComboBoxField.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        internal PdfComboBoxField(PdfDocument document)
 | 
			
		||||
            : base(document)
 | 
			
		||||
        { }
 | 
			
		||||
 | 
			
		||||
        internal PdfComboBoxField(PdfDictionary dict)
 | 
			
		||||
            : base(dict)
 | 
			
		||||
        { }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the index of the selected item.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public int SelectedIndex
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                string value = Elements.GetString(Keys.V);
 | 
			
		||||
                return IndexInOptArray(value);
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx		  
 | 
			
		||||
                if (value != -1) //R080325
 | 
			
		||||
                {
 | 
			
		||||
                    string key = ValueInOptArray(value);
 | 
			
		||||
                    Elements.SetString(Keys.V, key);
 | 
			
		||||
                    Elements.SetInteger("/I", value); //R080304 !!!!!!! sonst reagiert die Combobox <20>berhaupt nicht !!!!!
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the value of the field.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx		  
 | 
			
		||||
        public override PdfItem Value //R080304
 | 
			
		||||
        {
 | 
			
		||||
            get { return Elements[Keys.V]; }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                if (ReadOnly)
 | 
			
		||||
                    throw new InvalidOperationException("The field is read only.");
 | 
			
		||||
                if (value is PdfString || value is PdfName)
 | 
			
		||||
                {
 | 
			
		||||
                    Elements[Keys.V] = value;
 | 
			
		||||
                    SelectedIndex = SelectedIndex; //R080304 !!!
 | 
			
		||||
                    if (SelectedIndex == -1)
 | 
			
		||||
                    {
 | 
			
		||||
                        //R080317 noch nicht rund
 | 
			
		||||
                        try
 | 
			
		||||
                        {
 | 
			
		||||
                            //anh<6E>ngen
 | 
			
		||||
                            ((PdfArray)(((PdfItem[])(Elements.Values))[2])).Elements.Add(Value);
 | 
			
		||||
                            SelectedIndex = SelectedIndex;
 | 
			
		||||
                        }
 | 
			
		||||
                        catch { }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                else
 | 
			
		||||
                    throw new NotImplementedException("Values other than string cannot be set.");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Predefined keys of this dictionary. 
 | 
			
		||||
        /// The description comes from PDF 1.4 Reference.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public new class Keys : PdfAcroField.Keys
 | 
			
		||||
        {
 | 
			
		||||
            // Combo boxes have no additional entries.
 | 
			
		||||
 | 
			
		||||
            internal static DictionaryMeta Meta
 | 
			
		||||
            {
 | 
			
		||||
                get
 | 
			
		||||
                {
 | 
			
		||||
                    if (Keys._meta == null)
 | 
			
		||||
                        Keys._meta = CreateMeta(typeof(Keys));
 | 
			
		||||
                    return Keys._meta;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            static DictionaryMeta _meta;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the KeysMeta of this dictionary type.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        internal override DictionaryMeta Meta
 | 
			
		||||
        {
 | 
			
		||||
            get { return Keys.Meta; }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										69
									
								
								PrintPDF/PdfSharp/Pdf.AcroForms/PdfGenericField.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								PrintPDF/PdfSharp/Pdf.AcroForms/PdfGenericField.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,69 @@
 | 
			
		||||
#region PDFsharp - A .NET library for processing PDF
 | 
			
		||||
//
 | 
			
		||||
// Authors:
 | 
			
		||||
//   Stefan Lange
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2005-2017 empira Software GmbH, Cologne Area (Germany)
 | 
			
		||||
//
 | 
			
		||||
// http://www.pdfsharp.com
 | 
			
		||||
// http://sourceforge.net/projects/pdfsharp
 | 
			
		||||
//
 | 
			
		||||
// Permission is hereby granted, free of charge, to any person obtaining a
 | 
			
		||||
// copy of this software and associated documentation files (the "Software"),
 | 
			
		||||
// to deal in the Software without restriction, including without limitation
 | 
			
		||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
 | 
			
		||||
// and/or sell copies of the Software, and to permit persons to whom the
 | 
			
		||||
// Software is furnished to do so, subject to the following conditions:
 | 
			
		||||
//
 | 
			
		||||
// The above copyright notice and this permission notice shall be included
 | 
			
		||||
// in all copies or substantial portions of the Software.
 | 
			
		||||
//
 | 
			
		||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 | 
			
		||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 | 
			
		||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 | 
			
		||||
// DEALINGS IN THE SOFTWARE.
 | 
			
		||||
#endregion
 | 
			
		||||
 | 
			
		||||
namespace PdfSharp.Pdf.AcroForms
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Represents a generic field. Used for AcroForm dictionaries unknown to PDFsharp.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public sealed class PdfGenericField : PdfAcroField
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Initializes a new instance of PdfGenericField.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        internal PdfGenericField(PdfDocument document)
 | 
			
		||||
            : base(document)
 | 
			
		||||
        { }
 | 
			
		||||
 | 
			
		||||
        internal PdfGenericField(PdfDictionary dict)
 | 
			
		||||
            : base(dict)
 | 
			
		||||
        { }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Predefined keys of this dictionary. 
 | 
			
		||||
        /// The description comes from PDF 1.4 Reference.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public new class Keys : PdfAcroField.Keys
 | 
			
		||||
        {
 | 
			
		||||
            internal static DictionaryMeta Meta
 | 
			
		||||
            {
 | 
			
		||||
                get { return _meta ?? (_meta = CreateMeta(typeof(Keys))); }
 | 
			
		||||
            }
 | 
			
		||||
            static DictionaryMeta _meta;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the KeysMeta of this dictionary type.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        internal override DictionaryMeta Meta
 | 
			
		||||
        {
 | 
			
		||||
            get { return Keys.Meta; }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										88
									
								
								PrintPDF/PdfSharp/Pdf.AcroForms/PdfListBoxField.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								PrintPDF/PdfSharp/Pdf.AcroForms/PdfListBoxField.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,88 @@
 | 
			
		||||
#region PDFsharp - A .NET library for processing PDF
 | 
			
		||||
//
 | 
			
		||||
// Authors:
 | 
			
		||||
//   Stefan Lange
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2005-2017 empira Software GmbH, Cologne Area (Germany)
 | 
			
		||||
//
 | 
			
		||||
// http://www.pdfsharp.com
 | 
			
		||||
// http://sourceforge.net/projects/pdfsharp
 | 
			
		||||
//
 | 
			
		||||
// Permission is hereby granted, free of charge, to any person obtaining a
 | 
			
		||||
// copy of this software and associated documentation files (the "Software"),
 | 
			
		||||
// to deal in the Software without restriction, including without limitation
 | 
			
		||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
 | 
			
		||||
// and/or sell copies of the Software, and to permit persons to whom the
 | 
			
		||||
// Software is furnished to do so, subject to the following conditions:
 | 
			
		||||
//
 | 
			
		||||
// The above copyright notice and this permission notice shall be included
 | 
			
		||||
// in all copies or substantial portions of the Software.
 | 
			
		||||
//
 | 
			
		||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 | 
			
		||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 | 
			
		||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 | 
			
		||||
// DEALINGS IN THE SOFTWARE.
 | 
			
		||||
#endregion
 | 
			
		||||
 | 
			
		||||
namespace PdfSharp.Pdf.AcroForms
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Represents the list box field.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public sealed class PdfListBoxField : PdfChoiceField
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Initializes a new instance of PdfListBoxField.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        internal PdfListBoxField(PdfDocument document)
 | 
			
		||||
            : base(document)
 | 
			
		||||
        { }
 | 
			
		||||
 | 
			
		||||
        internal PdfListBoxField(PdfDictionary dict)
 | 
			
		||||
            : base(dict)
 | 
			
		||||
        { }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the index of the selected item
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public int SelectedIndex
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                string value = Elements.GetString(Keys.V);
 | 
			
		||||
                return IndexInOptArray(value);
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                string key = ValueInOptArray(value);
 | 
			
		||||
                Elements.SetString(Keys.V, key);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Predefined keys of this dictionary. 
 | 
			
		||||
        /// The description comes from PDF 1.4 Reference.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public new class Keys : PdfAcroField.Keys
 | 
			
		||||
        {
 | 
			
		||||
            // List boxes have no additional entries.
 | 
			
		||||
 | 
			
		||||
            internal static DictionaryMeta Meta
 | 
			
		||||
            {
 | 
			
		||||
                get { return _meta ?? (_meta = CreateMeta(typeof(Keys))); }
 | 
			
		||||
            }
 | 
			
		||||
            static DictionaryMeta _meta;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the KeysMeta of this dictionary type.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        internal override DictionaryMeta Meta
 | 
			
		||||
        {
 | 
			
		||||
            get { return Keys.Meta; }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										71
									
								
								PrintPDF/PdfSharp/Pdf.AcroForms/PdfPushButtonField.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								PrintPDF/PdfSharp/Pdf.AcroForms/PdfPushButtonField.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,71 @@
 | 
			
		||||
#region PDFsharp - A .NET library for processing PDF
 | 
			
		||||
//
 | 
			
		||||
// Authors:
 | 
			
		||||
//   Stefan Lange
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2005-2017 empira Software GmbH, Cologne Area (Germany)
 | 
			
		||||
//
 | 
			
		||||
// http://www.pdfsharp.com
 | 
			
		||||
// http://sourceforge.net/projects/pdfsharp
 | 
			
		||||
//
 | 
			
		||||
// Permission is hereby granted, free of charge, to any person obtaining a
 | 
			
		||||
// copy of this software and associated documentation files (the "Software"),
 | 
			
		||||
// to deal in the Software without restriction, including without limitation
 | 
			
		||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
 | 
			
		||||
// and/or sell copies of the Software, and to permit persons to whom the
 | 
			
		||||
// Software is furnished to do so, subject to the following conditions:
 | 
			
		||||
//
 | 
			
		||||
// The above copyright notice and this permission notice shall be included
 | 
			
		||||
// in all copies or substantial portions of the Software.
 | 
			
		||||
//
 | 
			
		||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 | 
			
		||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 | 
			
		||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 | 
			
		||||
// DEALINGS IN THE SOFTWARE.
 | 
			
		||||
#endregion
 | 
			
		||||
 | 
			
		||||
namespace PdfSharp.Pdf.AcroForms
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Represents the push button field.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public sealed class PdfPushButtonField : PdfButtonField
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Initializes a new instance of PdfPushButtonField.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        internal PdfPushButtonField(PdfDocument document)
 | 
			
		||||
            : base(document)
 | 
			
		||||
        {
 | 
			
		||||
            _document = document;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        internal PdfPushButtonField(PdfDictionary dict)
 | 
			
		||||
            : base(dict)
 | 
			
		||||
        { }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Predefined keys of this dictionary. 
 | 
			
		||||
        /// The description comes from PDF 1.4 Reference.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public new class Keys : PdfAcroField.Keys
 | 
			
		||||
        {
 | 
			
		||||
            internal static DictionaryMeta Meta
 | 
			
		||||
            {
 | 
			
		||||
                get { return _meta ?? (_meta = CreateMeta(typeof(Keys))); }
 | 
			
		||||
            }
 | 
			
		||||
            static DictionaryMeta _meta;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the KeysMeta of this dictionary type.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        internal override DictionaryMeta Meta
 | 
			
		||||
        {
 | 
			
		||||
            get { return Keys.Meta; }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										132
									
								
								PrintPDF/PdfSharp/Pdf.AcroForms/PdfRadioButtonField.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										132
									
								
								PrintPDF/PdfSharp/Pdf.AcroForms/PdfRadioButtonField.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,132 @@
 | 
			
		||||
#region PDFsharp - A .NET library for processing PDF
 | 
			
		||||
//
 | 
			
		||||
// Authors:
 | 
			
		||||
//   Stefan Lange
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2005-2017 empira Software GmbH, Cologne Area (Germany)
 | 
			
		||||
//
 | 
			
		||||
// http://www.pdfsharp.com
 | 
			
		||||
// http://sourceforge.net/projects/pdfsharp
 | 
			
		||||
//
 | 
			
		||||
// Permission is hereby granted, free of charge, to any person obtaining a
 | 
			
		||||
// copy of this software and associated documentation files (the "Software"),
 | 
			
		||||
// to deal in the Software without restriction, including without limitation
 | 
			
		||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
 | 
			
		||||
// and/or sell copies of the Software, and to permit persons to whom the
 | 
			
		||||
// Software is furnished to do so, subject to the following conditions:
 | 
			
		||||
//
 | 
			
		||||
// The above copyright notice and this permission notice shall be included
 | 
			
		||||
// in all copies or substantial portions of the Software.
 | 
			
		||||
//
 | 
			
		||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 | 
			
		||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 | 
			
		||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 | 
			
		||||
// DEALINGS IN THE SOFTWARE.
 | 
			
		||||
#endregion
 | 
			
		||||
 | 
			
		||||
using System;
 | 
			
		||||
 | 
			
		||||
namespace PdfSharp.Pdf.AcroForms
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Represents the radio button field.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public sealed class PdfRadioButtonField : PdfButtonField
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Initializes a new instance of PdfRadioButtonField.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        internal PdfRadioButtonField(PdfDocument document)
 | 
			
		||||
            : base(document)
 | 
			
		||||
        {
 | 
			
		||||
            _document = document;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        internal PdfRadioButtonField(PdfDictionary dict)
 | 
			
		||||
            : base(dict)
 | 
			
		||||
        { }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the index of the selected radio button in a radio button group.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public int SelectedIndex
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                string value = Elements.GetString(Keys.V);
 | 
			
		||||
                return IndexInOptStrings(value);
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                PdfArray opt = Elements[Keys.Opt] as PdfArray;
 | 
			
		||||
 | 
			
		||||
                if (opt == null)
 | 
			
		||||
                    opt = Elements[Keys.Kids] as PdfArray;
 | 
			
		||||
 | 
			
		||||
                if (opt != null)
 | 
			
		||||
                {
 | 
			
		||||
                    int count = opt.Elements.Count;
 | 
			
		||||
                    if (value < 0 || value >= count)
 | 
			
		||||
                        throw new ArgumentOutOfRangeException("value");
 | 
			
		||||
                    Elements.SetName(Keys.V, opt.Elements[value].ToString());
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int IndexInOptStrings(string value)
 | 
			
		||||
        {
 | 
			
		||||
            PdfArray opt = Elements[Keys.Opt] as PdfArray;
 | 
			
		||||
            if (opt != null)
 | 
			
		||||
            {
 | 
			
		||||
                int count = opt.Elements.Count;
 | 
			
		||||
                for (int idx = 0; idx < count; idx++)
 | 
			
		||||
                {
 | 
			
		||||
                    PdfItem item = opt.Elements[idx];
 | 
			
		||||
                    if (item is PdfString)
 | 
			
		||||
                    {
 | 
			
		||||
                        if (item.ToString() == value)
 | 
			
		||||
                            return idx;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            return -1;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Predefined keys of this dictionary. 
 | 
			
		||||
        /// The description comes from PDF 1.4 Reference.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public new class Keys : PdfButtonField.Keys
 | 
			
		||||
        {
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Optional; inheritable; PDF 1.4) An array of text strings to be used in
 | 
			
		||||
            /// place of the V entries for the values of the widget annotations representing
 | 
			
		||||
            /// the individual radio buttons. Each element in the array represents
 | 
			
		||||
            /// the export value of the corresponding widget annotation in the
 | 
			
		||||
            /// Kids array of the radio button field.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo(KeyType.Array | KeyType.Optional)]
 | 
			
		||||
            public const string Opt = "/Opt";
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// Gets the KeysMeta for these keys.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            internal static DictionaryMeta Meta
 | 
			
		||||
            {
 | 
			
		||||
                get { return _meta ?? (_meta = CreateMeta(typeof(Keys))); }
 | 
			
		||||
            }
 | 
			
		||||
            static DictionaryMeta _meta;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the KeysMeta of this dictionary type.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        internal override DictionaryMeta Meta
 | 
			
		||||
        {
 | 
			
		||||
            get { return Keys.Meta; }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										134
									
								
								PrintPDF/PdfSharp/Pdf.AcroForms/PdfSignatureField.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										134
									
								
								PrintPDF/PdfSharp/Pdf.AcroForms/PdfSignatureField.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,134 @@
 | 
			
		||||
#region PDFsharp - A .NET library for processing PDF
 | 
			
		||||
//
 | 
			
		||||
// Authors:
 | 
			
		||||
//   Stefan Lange
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2005-2017 empira Software GmbH, Cologne Area (Germany)
 | 
			
		||||
//
 | 
			
		||||
// http://www.pdfsharp.com
 | 
			
		||||
// http://sourceforge.net/projects/pdfsharp
 | 
			
		||||
//
 | 
			
		||||
// Permission is hereby granted, free of charge, to any person obtaining a
 | 
			
		||||
// copy of this software and associated documentation files (the "Software"),
 | 
			
		||||
// to deal in the Software without restriction, including without limitation
 | 
			
		||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
 | 
			
		||||
// and/or sell copies of the Software, and to permit persons to whom the
 | 
			
		||||
// Software is furnished to do so, subject to the following conditions:
 | 
			
		||||
//
 | 
			
		||||
// The above copyright notice and this permission notice shall be included
 | 
			
		||||
// in all copies or substantial portions of the Software.
 | 
			
		||||
//
 | 
			
		||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 | 
			
		||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 | 
			
		||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 | 
			
		||||
// DEALINGS IN THE SOFTWARE.
 | 
			
		||||
#endregion
 | 
			
		||||
 | 
			
		||||
namespace PdfSharp.Pdf.AcroForms
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Represents the signature field.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public sealed class PdfSignatureField : PdfAcroField
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Initializes a new instance of PdfSignatureField.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        internal PdfSignatureField(PdfDocument document)
 | 
			
		||||
            : base(document)
 | 
			
		||||
        { }
 | 
			
		||||
 | 
			
		||||
        internal PdfSignatureField(PdfDictionary dict)
 | 
			
		||||
            : base(dict)
 | 
			
		||||
        { }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Predefined keys of this dictionary.
 | 
			
		||||
        /// The description comes from PDF 1.4 Reference.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public new class Keys : PdfAcroField.Keys
 | 
			
		||||
        {
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Optional) The type of PDF object that this dictionary describes; if present,
 | 
			
		||||
            /// must be Sig for a signature dictionary.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo(KeyType.Name | KeyType.Optional)]
 | 
			
		||||
            public const string Type = "/Type";
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Required; inheritable) The name of the signature handler to be used for
 | 
			
		||||
            /// authenticating the field<6C>s contents, such as Adobe.PPKLite, Entrust.PPKEF,
 | 
			
		||||
            /// CICI.SignIt, or VeriSign.PPKVS.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo(KeyType.Name | KeyType.Required)]
 | 
			
		||||
            public const string Filter = "/Filter";
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Optional) The name of a specific submethod of the specified handler.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo(KeyType.Name | KeyType.Optional)]
 | 
			
		||||
            public const string SubFilter = "/SubFilter";
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Required) An array of pairs of integers (starting byte offset, length in bytes)
 | 
			
		||||
            /// describing the exact byte range for the digest calculation. Multiple discontinuous
 | 
			
		||||
            /// byte ranges may be used to describe a digest that does not include the
 | 
			
		||||
            /// signature token itself.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo(KeyType.Array | KeyType.Required)]
 | 
			
		||||
            public const string ByteRange = "/ByteRange";
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Required) The encrypted signature token.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo(KeyType.String | KeyType.Required)]
 | 
			
		||||
            public const string Contents = "/Contents";
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Optional) The name of the person or authority signing the document.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo(KeyType.TextString | KeyType.Optional)]
 | 
			
		||||
            public const string Name = "/Name";
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Optional) The time of signing. Depending on the signature handler, this
 | 
			
		||||
            /// may be a normal unverified computer time or a time generated in a verifiable
 | 
			
		||||
            /// way from a secure time server.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo(KeyType.Date | KeyType.Optional)]
 | 
			
		||||
            public const string M = "/M";
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Optional) The CPU host name or physical location of the signing.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo(KeyType.TextString | KeyType.Optional)]
 | 
			
		||||
            public const string Location = "/Location";
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Optional) The reason for the signing, such as (I agree<65>).
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo(KeyType.TextString | KeyType.Optional)]
 | 
			
		||||
            public const string Reason = "/Reason";
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// Gets the KeysMeta for these keys.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            internal static DictionaryMeta Meta
 | 
			
		||||
            {
 | 
			
		||||
                get { return _meta ?? (_meta = CreateMeta(typeof(Keys))); }
 | 
			
		||||
            }
 | 
			
		||||
            static DictionaryMeta _meta;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the KeysMeta of this dictionary type.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        internal override DictionaryMeta Meta
 | 
			
		||||
        {
 | 
			
		||||
            get { return Keys.Meta; }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										309
									
								
								PrintPDF/PdfSharp/Pdf.AcroForms/PdfTextField.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										309
									
								
								PrintPDF/PdfSharp/Pdf.AcroForms/PdfTextField.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,309 @@
 | 
			
		||||
#region PDFsharp - A .NET library for processing PDF
 | 
			
		||||
//
 | 
			
		||||
// Authors:
 | 
			
		||||
//   Stefan Lange
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2005-2017 empira Software GmbH, Cologne Area (Germany)
 | 
			
		||||
//
 | 
			
		||||
// http://www.pdfsharp.com
 | 
			
		||||
// http://sourceforge.net/projects/pdfsharp
 | 
			
		||||
//
 | 
			
		||||
// Permission is hereby granted, free of charge, to any person obtaining a
 | 
			
		||||
// copy of this software and associated documentation files (the "Software"),
 | 
			
		||||
// to deal in the Software without restriction, including without limitation
 | 
			
		||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
 | 
			
		||||
// and/or sell copies of the Software, and to permit persons to whom the
 | 
			
		||||
// Software is furnished to do so, subject to the following conditions:
 | 
			
		||||
//
 | 
			
		||||
// The above copyright notice and this permission notice shall be included
 | 
			
		||||
// in all copies or substantial portions of the Software.
 | 
			
		||||
//
 | 
			
		||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 | 
			
		||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 | 
			
		||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 | 
			
		||||
// DEALINGS IN THE SOFTWARE.
 | 
			
		||||
#endregion
 | 
			
		||||
 | 
			
		||||
using PdfSharp.Drawing;
 | 
			
		||||
using PdfSharp.Pdf.Advanced;
 | 
			
		||||
using PdfSharp.Pdf.Annotations;
 | 
			
		||||
using PdfSharp.Pdf.Internal;
 | 
			
		||||
 | 
			
		||||
namespace PdfSharp.Pdf.AcroForms
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Represents the text field.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public sealed class PdfTextField : PdfAcroField
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Initializes a new instance of PdfTextField.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        internal PdfTextField(PdfDocument document)
 | 
			
		||||
            : base(document)
 | 
			
		||||
        { }
 | 
			
		||||
 | 
			
		||||
        internal PdfTextField(PdfDictionary dict)
 | 
			
		||||
            : base(dict)
 | 
			
		||||
        { }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the text value of the text field.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string Text
 | 
			
		||||
        {
 | 
			
		||||
            get { return Elements.GetString(Keys.V); }
 | 
			
		||||
            set { Elements.SetString(Keys.V, value); RenderAppearance(); } //HACK in PdfTextField
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the font used to draw the text of the field.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public XFont Font
 | 
			
		||||
        {
 | 
			
		||||
            get { return _font; }
 | 
			
		||||
            set { _font = value; }
 | 
			
		||||
        }
 | 
			
		||||
        XFont _font = new XFont("Courier New", 10);
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the foreground color of the field.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public XColor ForeColor
 | 
			
		||||
        {
 | 
			
		||||
            get { return _foreColor; }
 | 
			
		||||
            set { _foreColor = value; }
 | 
			
		||||
        }
 | 
			
		||||
        XColor _foreColor = XColors.Black;
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the background color of the field.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public XColor BackColor
 | 
			
		||||
        {
 | 
			
		||||
            get { return _backColor; }
 | 
			
		||||
            set { _backColor = value; }
 | 
			
		||||
        }
 | 
			
		||||
        XColor _backColor = XColor.Empty;
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the maximum length of the field.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <value>The length of the max.</value>
 | 
			
		||||
        public int MaxLength
 | 
			
		||||
        {
 | 
			
		||||
            get { return Elements.GetInteger(Keys.MaxLen); }
 | 
			
		||||
            set { Elements.SetInteger(Keys.MaxLen, value); }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets a value indicating whether the field has multiple lines.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public bool MultiLine
 | 
			
		||||
        {
 | 
			
		||||
            get { return (Flags & PdfAcroFieldFlags.Multiline) != 0; }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                if (value)
 | 
			
		||||
                    SetFlags |= PdfAcroFieldFlags.Multiline;
 | 
			
		||||
                else
 | 
			
		||||
                    SetFlags &= ~PdfAcroFieldFlags.Multiline;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets a value indicating whether this field is used for passwords.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public bool Password
 | 
			
		||||
        {
 | 
			
		||||
            get { return (Flags & PdfAcroFieldFlags.Password) != 0; }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                if (value)
 | 
			
		||||
                    SetFlags |= PdfAcroFieldFlags.Password;
 | 
			
		||||
                else
 | 
			
		||||
                    SetFlags &= ~PdfAcroFieldFlags.Password;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Creates the normal appearance form X object for the annotation that represents
 | 
			
		||||
        /// this acro form text field.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        void RenderAppearance()
 | 
			
		||||
        {
 | 
			
		||||
#if true_
 | 
			
		||||
            PdfFormXObject xobj = new PdfFormXObject(Owner);
 | 
			
		||||
            Owner.Internals.AddObject(xobj);
 | 
			
		||||
            xobj.Elements["/BBox"] = new PdfLiteral("[0 0 122.653 12.707]");
 | 
			
		||||
            xobj.Elements["/FormType"] = new PdfLiteral("1");
 | 
			
		||||
            xobj.Elements["/Matrix"] = new PdfLiteral("[1 0 0 1 0 0]");
 | 
			
		||||
            PdfDictionary res = new PdfDictionary(Owner);
 | 
			
		||||
            xobj.Elements["/Resources"] = res;
 | 
			
		||||
            res.Elements["/Font"] = new PdfLiteral("<< /Helv 28 0 R >> /ProcSet [/PDF /Text]");
 | 
			
		||||
            xobj.Elements["/Subtype"] = new PdfLiteral("/Form");
 | 
			
		||||
            xobj.Elements["/Type"] = new PdfLiteral("/XObject");
 | 
			
		||||
 | 
			
		||||
            string s =
 | 
			
		||||
              "/Tx BMC " + '\n' +
 | 
			
		||||
              "q" + '\n' +
 | 
			
		||||
              "1 1 120.653 10.707 re" + '\n' +
 | 
			
		||||
              "W" + '\n' +
 | 
			
		||||
              "n" + '\n' +
 | 
			
		||||
              "BT" + '\n' +
 | 
			
		||||
              "/Helv 7.93 Tf" + '\n' +
 | 
			
		||||
              "0 g" + '\n' +
 | 
			
		||||
              "2 3.412 Td" + '\n' +
 | 
			
		||||
              "(Hello ) Tj" + '\n' +
 | 
			
		||||
              "20.256 0 Td" + '\n' +
 | 
			
		||||
              "(XXX) Tj" + '\n' +
 | 
			
		||||
              "ET" + '\n' +
 | 
			
		||||
              "Q" + '\n' +
 | 
			
		||||
              "";//"EMC";
 | 
			
		||||
            int length = s.Length;
 | 
			
		||||
            byte[] stream = new byte[length];
 | 
			
		||||
            for (int idx = 0; idx < length; idx++)
 | 
			
		||||
                stream[idx] = (byte)s[idx];
 | 
			
		||||
            xobj.CreateStream(stream);
 | 
			
		||||
 | 
			
		||||
            // Get existing or create new appearance dictionary
 | 
			
		||||
            PdfDictionary ap = Elements[PdfAnnotation.Keys.AP] as PdfDictionary;
 | 
			
		||||
            if (ap == null)
 | 
			
		||||
            {
 | 
			
		||||
                ap = new PdfDictionary(_document);
 | 
			
		||||
                Elements[PdfAnnotation.Keys.AP] = ap;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // Set XRef to normal state
 | 
			
		||||
            ap.Elements["/N"] = xobj.Reference;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            //// HACK
 | 
			
		||||
            //string m =
 | 
			
		||||
            //"<?xpacket begin=\"\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>" + '\n' +
 | 
			
		||||
            //"<x:xmpmeta xmlns:x=\"adobe:ns:meta/\" x:xmptk=\"Adobe XMP Core 4.0-c321 44.398116, Tue Aug 04 2009 14:24:39\"> " + '\n' +
 | 
			
		||||
            //"   <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"> " + '\n' +
 | 
			
		||||
            //"      <rdf:Description rdf:about=\"\" " + '\n' +
 | 
			
		||||
            //"            xmlns:pdf=\"http://ns.adobe.com/pdf/1.3/\"> " + '\n' +
 | 
			
		||||
            //"         <pdf:Producer>PDFsharp 1.40.2150-g (www.pdfsharp.com) (Original: Powered By Crystal)</pdf:Producer> " + '\n' +
 | 
			
		||||
            //"      </rdf:Description> " + '\n' +
 | 
			
		||||
            //"      <rdf:Description rdf:about=\"\" " + '\n' +
 | 
			
		||||
            //"            xmlns:xap=\"http://ns.adobe.com/xap/1.0/\"> " + '\n' +
 | 
			
		||||
            //"         <xap:ModifyDate>2011-07-11T23:15:09+02:00</xap:ModifyDate> " + '\n' +
 | 
			
		||||
            //"         <xap:CreateDate>2011-05-19T16:26:51+03:00</xap:CreateDate> " + '\n' +
 | 
			
		||||
            //"         <xap:MetadataDate>2011-07-11T23:15:09+02:00</xap:MetadataDate> " + '\n' +
 | 
			
		||||
            //"         <xap:CreatorTool>Crystal Reports</xap:CreatorTool> " + '\n' +
 | 
			
		||||
            //"      </rdf:Description> " + '\n' +
 | 
			
		||||
            //"      <rdf:Description rdf:about=\"\" " + '\n' +
 | 
			
		||||
            //"            xmlns:dc=\"http://purl.org/dc/elements/1.1/\"> " + '\n' +
 | 
			
		||||
            //"         <dc:format>application/pdf</dc:format> " + '\n' +
 | 
			
		||||
            //"      </rdf:Description> " + '\n' +
 | 
			
		||||
            //"      <rdf:Description rdf:about=\"\" " + '\n' +
 | 
			
		||||
            //"            xmlns:xapMM=\"http://ns.adobe.com/xap/1.0/mm/\"> " + '\n' +
 | 
			
		||||
            //"         <xapMM:DocumentID>uuid:68249d89-baed-4384-9a2d-fbf8ace75c45</xapMM:DocumentID> " + '\n' +
 | 
			
		||||
            //"         <xapMM:InstanceID>uuid:3d5f2f46-c140-416f-baf2-7f9c970cef1d</xapMM:InstanceID> " + '\n' +
 | 
			
		||||
            //"      </rdf:Description> " + '\n' +
 | 
			
		||||
            //"   </rdf:RDF> " + '\n' +
 | 
			
		||||
            //"</x:xmpmeta> " + '\n' +
 | 
			
		||||
            //"                                                                          " + '\n' +
 | 
			
		||||
            //"                                                                          " + '\n' +
 | 
			
		||||
            //"                                                                          " + '\n' +
 | 
			
		||||
            //"                                                                          " + '\n' +
 | 
			
		||||
            //"                                                                          " + '\n' +
 | 
			
		||||
            //"                                                                          " + '\n' +
 | 
			
		||||
            //"                                                                          " + '\n' +
 | 
			
		||||
            //"                                                                          " + '\n' +
 | 
			
		||||
            //"                                                                          " + '\n' +
 | 
			
		||||
            //"                                                                          " + '\n' +
 | 
			
		||||
            //"<?xpacket end=\"w\"?>";
 | 
			
		||||
 | 
			
		||||
            //PdfDictionary mdict = (PdfDictionary)_document.Internals.GetObject(new PdfObjectID(32));
 | 
			
		||||
 | 
			
		||||
            //length = m.Length;
 | 
			
		||||
            //stream = new byte[length];
 | 
			
		||||
            //for (int idx = 0; idx < length; idx++)
 | 
			
		||||
            //  stream[idx] = (byte)m[idx];
 | 
			
		||||
 | 
			
		||||
            //mdict.Stream.Value = stream;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#else
 | 
			
		||||
            PdfRectangle rect = Elements.GetRectangle(PdfAnnotation.Keys.Rect);
 | 
			
		||||
            XForm form = new XForm(_document, rect.Size);
 | 
			
		||||
            XGraphics gfx = XGraphics.FromForm(form);
 | 
			
		||||
 | 
			
		||||
            if (_backColor != XColor.Empty)
 | 
			
		||||
                gfx.DrawRectangle(new XSolidBrush(BackColor), rect.ToXRect() - rect.Location);
 | 
			
		||||
 | 
			
		||||
            string text = Text;
 | 
			
		||||
            if (text.Length > 0)
 | 
			
		||||
                gfx.DrawString(Text, Font, new XSolidBrush(ForeColor),
 | 
			
		||||
                  rect.ToXRect() - rect.Location + new XPoint(2, 0), XStringFormats.TopLeft);
 | 
			
		||||
 | 
			
		||||
            form.DrawingFinished();
 | 
			
		||||
            form.PdfForm.Elements.Add("/FormType", new PdfLiteral("1"));
 | 
			
		||||
 | 
			
		||||
            // Get existing or create new appearance dictionary.
 | 
			
		||||
            PdfDictionary ap = Elements[PdfAnnotation.Keys.AP] as PdfDictionary;
 | 
			
		||||
            if (ap == null)
 | 
			
		||||
            {
 | 
			
		||||
                ap = new PdfDictionary(_document);
 | 
			
		||||
                Elements[PdfAnnotation.Keys.AP] = ap;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // Set XRef to normal state
 | 
			
		||||
            ap.Elements["/N"] = form.PdfForm.Reference;
 | 
			
		||||
 | 
			
		||||
            PdfFormXObject xobj = form.PdfForm;
 | 
			
		||||
            string s = xobj.Stream.ToString();
 | 
			
		||||
            // Thank you Adobe: Without putting the content in 'EMC brackets'
 | 
			
		||||
            // the text is not rendered by PDF Reader 9 or higher.
 | 
			
		||||
            s = "/Tx BMC\n" + s + "\nEMC";
 | 
			
		||||
            xobj.Stream.Value = new RawEncoding().GetBytes(s);
 | 
			
		||||
#endif
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        internal override void PrepareForSave()
 | 
			
		||||
        {
 | 
			
		||||
            base.PrepareForSave();
 | 
			
		||||
            RenderAppearance();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Predefined keys of this dictionary. 
 | 
			
		||||
        /// The description comes from PDF 1.4 Reference.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public new class Keys : PdfAcroField.Keys
 | 
			
		||||
        {
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// (Optional; inheritable) The maximum length of the field<6C>s text, in characters.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            [KeyInfo(KeyType.Integer | KeyType.Optional)]
 | 
			
		||||
            public const string MaxLen = "/MaxLen";
 | 
			
		||||
 | 
			
		||||
            /// <summary>
 | 
			
		||||
            /// Gets the KeysMeta for these keys.
 | 
			
		||||
            /// </summary>
 | 
			
		||||
            internal static DictionaryMeta Meta
 | 
			
		||||
            {
 | 
			
		||||
                get { return _meta ?? (_meta = CreateMeta(typeof(Keys))); }
 | 
			
		||||
            }
 | 
			
		||||
            static DictionaryMeta _meta;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the KeysMeta of this dictionary type.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        internal override DictionaryMeta Meta
 | 
			
		||||
        {
 | 
			
		||||
            get { return Keys.Meta; }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										151
									
								
								PrintPDF/PdfSharp/Pdf.AcroForms/enums/PdfAcroFieldFlags.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										151
									
								
								PrintPDF/PdfSharp/Pdf.AcroForms/enums/PdfAcroFieldFlags.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,151 @@
 | 
			
		||||
#region PDFsharp - A .NET library for processing PDF
 | 
			
		||||
//
 | 
			
		||||
// Authors:
 | 
			
		||||
//   Stefan Lange
 | 
			
		||||
//
 | 
			
		||||
// Copyright (c) 2005-2017 empira Software GmbH, Cologne Area (Germany)
 | 
			
		||||
//
 | 
			
		||||
// http://www.pdfsharp.com
 | 
			
		||||
// http://sourceforge.net/projects/pdfsharp
 | 
			
		||||
//
 | 
			
		||||
// Permission is hereby granted, free of charge, to any person obtaining a
 | 
			
		||||
// copy of this software and associated documentation files (the "Software"),
 | 
			
		||||
// to deal in the Software without restriction, including without limitation
 | 
			
		||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
 | 
			
		||||
// and/or sell copies of the Software, and to permit persons to whom the
 | 
			
		||||
// Software is furnished to do so, subject to the following conditions:
 | 
			
		||||
//
 | 
			
		||||
// The above copyright notice and this permission notice shall be included
 | 
			
		||||
// in all copies or substantial portions of the Software.
 | 
			
		||||
//
 | 
			
		||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 | 
			
		||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 | 
			
		||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 | 
			
		||||
// DEALINGS IN THE SOFTWARE.
 | 
			
		||||
#endregion
 | 
			
		||||
 | 
			
		||||
using System;
 | 
			
		||||
 | 
			
		||||
namespace PdfSharp.Pdf.AcroForms
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Specifies the flags of AcroForm fields.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [Flags]
 | 
			
		||||
    public enum PdfAcroFieldFlags
 | 
			
		||||
    {
 | 
			
		||||
        // ----- Common to all fields -----------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// If set, the user may not change the value of the field. Any associated widget
 | 
			
		||||
        /// annotations will not interact with the user; that is, they will not respond to 
 | 
			
		||||
        /// mouse clicks or change their appearance in response to mouse motions. This
 | 
			
		||||
        /// flag is useful for fields whose values are computed or imported from a database.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        ReadOnly = 1 << (1 - 1),
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// If set, the field must have a value at the time it is exported by a submit-form action.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        Required = 1 << (2 - 1),
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// If set, the field must not be exported by a submit-form action.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        NoExport = 1 << (3 - 1),
 | 
			
		||||
 | 
			
		||||
        // ----- Specific to button fields ------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// If set, the field is a pushbutton that does not retain a permanent value.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        Pushbutton = 1 << (17 - 1),
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// If set, the field is a set of radio buttons; if clear, the field is a checkbox.
 | 
			
		||||
        /// This flag is meaningful only if the Pushbutton flag is clear.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        Radio = 1 << (16 - 1),
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// (Radio buttons only) If set, exactly one radio button must be selected at all times;
 | 
			
		||||
        /// clicking the currently selected button has no effect. If clear, clicking
 | 
			
		||||
        /// the selected button deselects it, leaving no button selected.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        NoToggleToOff = 1 << (15 - 1),
 | 
			
		||||
 | 
			
		||||
        // ----- Specific to text fields --------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// If set, the field may contain multiple lines of text; if clear, the field<6C>s text
 | 
			
		||||
        /// is restricted to a single line.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        Multiline = 1 << (13 - 1),
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// If set, the field is intended for entering a secure password that should
 | 
			
		||||
        /// not be echoed visibly to the screen. Characters typed from the keyboard
 | 
			
		||||
        /// should instead be echoed in some unreadable form, such as
 | 
			
		||||
        /// asterisks or bullet characters.
 | 
			
		||||
        /// To protect password confidentiality, viewer applications should never
 | 
			
		||||
        /// store the value of the text field in the PDF file if this flag is set.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        Password = 1 << (14 - 1),
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// (PDF 1.4) If set, the text entered in the field represents the pathname of
 | 
			
		||||
        /// a file whose contents are to be submitted as the value of the field.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        FileSelect = 1 << (21 - 1),
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// (PDF 1.4) If set, the text entered in the field will not be spell-checked.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        DoNotSpellCheckTextField = 1 << (23 - 1),
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// (PDF 1.4) If set, the field will not scroll (horizontally for single-line
 | 
			
		||||
        /// fields, vertically for multiple-line fields) to accommodate more text
 | 
			
		||||
        /// than will fit within its annotation rectangle. Once the field is full, no
 | 
			
		||||
        /// further text will be accepted.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        DoNotScroll = 1 << (24 - 1),
 | 
			
		||||
 | 
			
		||||
        // ----- Specific to choice fields ------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// If set, the field is a combo box; if clear, the field is a list box.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        Combo = 1 << (18 - 1),
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// If set, the combo box includes an editable text box as well as a drop list;
 | 
			
		||||
        /// if clear, it includes only a drop list. This flag is meaningful only if the
 | 
			
		||||
        /// Combo flag is set.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        Edit = 1 << (19 - 1),
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// If set, the field<6C>s option items should be sorted alphabetically. This flag is
 | 
			
		||||
        /// intended for use by form authoring tools, not by PDF viewer applications;
 | 
			
		||||
        /// viewers should simply display the options in the order in which they occur 
 | 
			
		||||
        /// in the Opt array.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        Sort = 1 << (20 - 1),
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// (PDF 1.4) If set, more than one of the field<6C>s option items may be selected
 | 
			
		||||
        /// simultaneously; if clear, no more than one item at a time may be selected.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        MultiSelect = 1 << (22 - 1),
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// (PDF 1.4) If set, the text entered in the field will not be spell-checked.
 | 
			
		||||
        /// This flag is meaningful only if the Combo and Edit flags are both set.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        DoNotSpellCheckChoiseField = 1 << (23 - 1),
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user