⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pdfreader.cs

📁 pdf阅读器 用于阅读pdf格式的文件 方便 好用 免费的提供
💻 CS
📖 第 1 页 / 共 5 页
字号:
		{
			PdfName type = fieldDictionary.GetElement(FTName) as PdfName;
			if (type != null)
			{
				if (!type.Equals(ButtonName))
				{
					return false;
				}
			}
			else
			{
				return false;
			}

			return true;
		}
	}
	
	/// <summary>
	/// Represents a PushButton form field in a PDF document.
	/// See the PDF reference 8.6.3 Field Types.
	/// </summary>
	[CLSCompliant(true)]
	public class PdfPushButtonField: PdfButtonField
	{
		/// <summary>
		/// Initializes a new instance of PdfPushButtonField with the specified object number, generation number,
		/// and field dictionary.
		/// </summary>
		/// <param name="objNumber">The object number.</param>
		/// <param name="generationNumber">The generation number.</param>
		/// <param name="fieldDictionary">The field dictionary.</param>
		public PdfPushButtonField(int objNumber, int generationNumber, PdfDictionary fieldDictionary): base(objNumber,
			generationNumber, fieldDictionary)
		{
		}
	}

	/// <summary>
	/// Represents a set of RadioButton form fields in a PDF document.
	/// See the PDF reference 8.6.3 Field Types.
	/// </summary>
	[CLSCompliant(true)]
	public class PdfRadioButtonField: PdfButtonField
	{
		/// <summary>
		/// Initializes a new instance of PdfRadioButtonField with the specified object number, generation number,
		/// and field dictionary.
		/// </summary>
		/// <param name="objNumber">The object number.</param>
		/// <param name="generationNumber">The generation number.</param>
		/// <param name="fieldDictionary">The field dictionary.</param>
		public PdfRadioButtonField(int objNumber, int generationNumber, PdfDictionary fieldDictionary): base(objNumber,
			generationNumber, fieldDictionary)
		{
		}

		/// <summary>
		/// Gets or sets a value indicating the selected RadioButton.
		/// </summary>
		/// <value>The name of the selected RadioButton (without the leading '/').</value>
		public string SelectedItem
		{
			get
			{
				if (FieldDictionary.Dictionary.ContainsKey(VName) && FieldDictionary.Dictionary[VName].GetType() == typeof (PdfName))
				{
					PdfName selected = (PdfName)FieldDictionary.Dictionary[VName];
					return selected.ToString().Substring(1);
				}
				else
				{
					return "";
				}
			}

			set
			{
				FieldDictionary.SetElement(VName, new PdfName("/" + value));
			}
		}

		/// <summary>
		/// Gets or sets a value indicating if it is possible that no RadioButton is selected.
		/// </summary>
		/// <value>true if it is not possible that no RadioButton is selected.</value>
		public bool NoToggleToOff
		{
			get
			{
				return GetBit(15);
			}

			set
			{
				SetBit(15, value);
			}
		}
	}
	
	/// <summary>
	/// Represents a CheckBox form field in a PDF document.
	/// See the PDF reference 8.6.3 Field Types.
	/// </summary>
	[CLSCompliant(true)]
	public class PdfCheckBoxField: PdfButtonField
	{
		private PdfName OnState; // the Name object for the checked state, unchecked is always /Off
		private static PdfName OffState = new PdfName("/Off");
		private static PdfName ASName = new PdfName("/AS");

		/// <summary>
		/// Initializes a new instance of PdfCheckBoxField with the specified object number, generation number,
		/// and field dictionary.
		/// </summary>
		/// <param name="objNumber">The object number.</param>
		/// <param name="generationNumber">The generation number.</param>
		/// <param name="fieldDictionary">The field dictionary.</param>
		public PdfCheckBoxField(int objNumber, int generationNumber, PdfDictionary fieldDictionary): base(objNumber,
			generationNumber, fieldDictionary)
		{
			SetOnState();
		}

		private void SetOnState()
		{
			if (FieldDictionary.Dictionary.ContainsKey(APName) && FieldDictionary.Dictionary[APName].GetType() == typeof (PdfDictionary))
			{
				PdfDictionary appearance = (PdfDictionary)FieldDictionary.Dictionary[APName];
				if (appearance.Dictionary.ContainsKey(NName) && appearance.Dictionary[NName].GetType() == typeof (PdfDictionary))
				{
					PdfDictionary subAppearance = (PdfDictionary)appearance.Dictionary[NName];
					foreach (PdfName name in subAppearance.Dictionary.Keys)
					{
						if (!name.Equals(OffState))
						{
							OnState = name;
							break;
						}
					}
				}
			}
		}

		/// <summary>
		/// Gets or sets a value indicating whether the CheckBox is checked.
		/// </summary>
		/// <value>true is the CheckBox is checked.</value>
		public bool Checked
		{
			get
			{
				return FieldDictionary.Dictionary.ContainsKey(VName) && FieldDictionary.Dictionary[VName].Equals(OnState);
			}

			set
			{
				PdfName name = value ? OnState : OffState;
				FieldDictionary.SetElement(VName, name);
				FieldDictionary.SetElement(ASName, name);
			}
		}
	}

	/// <summary>
	/// Represents a Text form field in a PDF document, i.e. either a ListBox or a ComboBox.
	/// See the PDF reference 8.6.3 Field Types.
	/// </summary>
	[CLSCompliant(true)]
	public class PdfTXField: PdfField
	{
		/// <summary>
		/// Initializes a new instance of PdfTXField with the specified object number, generation number,
		/// and field dictionary.
		/// </summary>
		/// <param name="objNumber">The object number.</param>
		/// <param name="generationNumber">The generation number.</param>
		/// <param name="fieldDictionary">The field dictionary.</param>
		public PdfTXField(int objNumber, int generationNumber, PdfDictionary fieldDictionary): base(objNumber,
			generationNumber, fieldDictionary)
		{
			FieldDictionary.Dictionary.Remove(APName); // remove the appearance element, so it gets regenerated by the viewer
		}

		/// <summary>
		/// Gets or sets a value indicating the text that is displayed in the field.
		/// </summary>
		public string Text
		{
			get
			{
				if (FieldDictionary.Dictionary.ContainsKey(VName) && FieldDictionary.Dictionary[VName].GetType() == typeof (PdfString))
				{
					PdfString val = (PdfString)FieldDictionary.Dictionary[VName];
					return val.Text;
				}
				else
				{
					return "";
				}
			}

			set
			{
				PdfString val;
				string input = value + ")";
				val = new PdfString(false, ref input);

				FieldDictionary.SetElement(VName, val);
			}
		}

		/// <summary>
		/// Gets or sets a value indicating whether the field allows more than one line of input.
		/// </summary>
		/// <value>true if more than one line of input is allowed.</value>
		public bool MultiLine
		{
			get
			{
				return GetBit(13);
			}

			set
			{
				SetBit(13, value);
			}
		}

		/// <summary>
		/// Gets or sets a value indicating whether the text should be visibly echoed
		/// or instead rendered in a non-readable form such as asterisks or bullets.
		/// </summary>
		/// <value>true if the text should not be visibly echoed.</value>
		public bool Password
		{
			get
			{
				return GetBit(14);
			}

			set
			{
				SetBit(14, value);
			}
		}

		/// <summary>
		/// Gets or sets a value indicating whether this field represents the pathname of
		/// a file whose contents are to be submitted as the value of the field.
		/// </summary>
		/// <value>true if this field represents the pathname of a file.</value>
		public bool FileSelect
		{
			get
			{
				return GetBit(21);
			}

			set
			{
				SetBit(21, value);
			}
		}

		/// <summary>
		/// Gets or sets a value indicating whether spellchecking should be enabled.
		/// </summary>
		/// <value>true if no spell checking is performed.</value>
		public bool DoNotSpellCheck
		{
			get
			{
				return GetBit(23);
			}

			set
			{
				SetBit(23, value);
			}
		}

		/// <summary>
		/// Gets or sets a value indicating if scrolling is allowed.
		/// </summary>
		/// <value>true if this field should not allow scrolling.</value>
		public bool DoNotScroll
		{
			get
			{
				return GetBit(24);
			}

			set
			{
				SetBit(24, value);
			}
		}
	}

	/// <summary>
	/// Represents a Choice form field in a PDF document, i.e. either a ListBox or a ComboBox.
	/// See the PDF reference 8.6.3 Field Types.
	/// </summary>
	[CLSCompliant(true)]
	public class PdfCHField: PdfField
	{
		private static PdfName IName = new PdfName("/I");

		/// <summary>
		/// Initializes a new instance of PdfCHField with the specified object number, generation number,
		/// and field dictionary.
		/// </summary>
		/// <param name="objNumber">The object number.</param>
		/// <param name="generationNumber">The generation number.</param>
		/// <param name="fieldDictionary">The field dictionary.</param>
		public PdfCHField(int objNumber, int generationNumber, PdfDictionary fieldDictionary): base(objNumber,
			generationNumber, fieldDictionary)
		{
		}

		/// <summary>
		/// Gets or sets a value indicating whether this field should be rendered as a ComboBox or a ListBox.
		/// </summary>
		/// <value>true if the field should be rendered as ComboBox.</value>
		public bool Combo
		{
			get
			{
				return GetBit(18);
			}

			set
			{
				SetBit(18, value);
			}
		}

		/// <summary>
		/// Gets or sets a value indicating whether the ComboBox includes an editable text box as well as a drop list.
		/// This property is meaningful only if the Combo property is set to true.
		/// </summary>
		/// <value>true if the ComboBox should include an editable text box.</value>
		public bool Edit
		{
			get
			{
				return GetBit(19);
			}

			set
			{
				SetBit(19, value);
			}
		}

		/// <summary>
		/// Gets or sets a value indicating whether the fields elements are sorted alphabetically.
		/// </summary>
		/// <value>true if the elements are sorted alphabetically.</value>
		public bool Sort
		{
			get
			{
				return GetBit(20);
			}

			set
			{
				SetBit(20, value);
			}
		}

		/// <summary>
		/// Gets or sets a value indicating if more than one element is selectable.
		/// </summary>
		/// <value>true if more than one element is selectable.</value>
		public bool MultiSelect
		{
			get
			{
				return GetBit(22);
			}

			set
			{
				SetBit(22, value);
			}
		}

		/// <summary>
		/// Gets or sets a value indicating whether spellchecking should be enabled.
		/// This flag is meaningful only if the Combo and Edit flags are both set.
		/// </summary>
		/// <value>true if no spell checking is performed.</value>
		public bool DoNotSpellCheck
		{
			get
			{
				return GetBit(23);
			}

			set
			{
				SetBit(23, value);
			}
		}

		/// <summary>
		/// Sets the indexes of the items that should appear selected.
		/// </summary>
		/// <param name="indexes">The selected indexes.</param>
		public void SetSelectedIndexes(params int[] indexes)
		{
			if (indexes == null || indexes.Length <= 0)
			{
				FieldDictionary.SetElement(IName, new PdfNull());
			}
			else if (indexes.Length == 1)
			{
				PdfNumber val = new PdfNumber((double)indexes[0]);

				FieldDictionary.SetElement(IName, val);
			}
			else
			{
				PdfNumber[] items = new PdfNumber[indexes.Length];
				int i = 0;
				foreach (int index in indexes)
				{
					items[i] = new PdfNumber((double)index);
					i++;
				}
				
				PdfArray val = new PdfArray(items);
				FieldDictionary.SetElement(IName, val);
			}
		}

		/// <summary>
		/// Gets the indexes of the items that should appear selected.
		/// </summary>
		/// <returns>An array of index that are selected.</returns>
		public int[] GetSelectedIndexes()
		{
			PdfObject iObject = FieldDictionary.GetElement(IName);

			if (iObject == null || iObject.GetType() == typeof (PdfNull))
			{
				return new int[] {};
			}
			else if (iObject.GetType() == typeof (PdfNumber))
			{
				return new int[] { (int)((PdfNumber)iObject).Number };
			}
			else
			{
				PdfArray array = (PdfArray)iObject;
				int[] indexes = new int[array.Elements.Count];

				for (int i = 0; i < array.Elements.Count; i++)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -