private Element2D CreateComboBox(Frame vertLayout, XMLSettingsItem settings, ref int ID_Builder) { var slicerSettingsItem = settings.SlicerSettingsItem as SlicerSettingsEnumItem; var horzonalFrame = new Frame(ID_Builder++, vertLayout) { RelativeWidth = 1f, Height = 28 }; CreateSettingsTitleElement(horzonalFrame, ID_Builder++, settings.Text); var comboBoxWidget = new ComboBoxWidget(ID_Builder++, horzonalFrame) { Value = slicerSettingsItem.ValueInt, tag = settings.Name }; comboBoxWidget.Init(host); comboBoxWidget.ItemsEnumString = slicerSettingsItem.EnumType.ToString(); comboBoxWidget.Select = slicerSettingsItem.ValueInt; comboBoxWidget.ToolTipMessage = settings.Tooltip; comboBoxWidget.Height = 24; comboBoxWidget.Width = 240; comboBoxWidget.X = 245; comboBoxWidget.Size = FontSize.Medium; comboBoxWidget.HexColor = "#FF808080"; comboBoxWidget.TextChangedCallback += new ComboBoxWidget.ComboBoxTextChangedCallback(comboBoxChangedCallBack); horzonalFrame.AddChildElement(comboBoxWidget); vertLayout.AddChildElement(horzonalFrame); return(comboBoxWidget); }
public override void Init() { CreateManageFilamentFrame("Select 3D Ink Color", "", false, false, false, false, true, true); var childElement = (Frame)FindChildElement(2); if (childElement == null) { return; } var textWidget = new TextWidget(11) { Color = new Color4(0.35f, 0.35f, 0.35f, 1f), RelativeWidth = 1f, RelativeHeight = 0.2f, X = 0, Y = 20, Alignment = QFontAlignment.Centre, VAlignment = TextVerticalAlignment.Top, Text = "What Color is your filament?" }; childElement.AddChildElement(textWidget); color_combobox = new ComboBoxWidget(12); color_combobox.Init(Host); color_combobox.Select = 0; color_combobox.SetPosition(30, 60); color_combobox.SetSize(336, 32); color_combobox.CenterHorizontallyInParent = true; childElement.AddChildElement(color_combobox); color_combobox.ListBox.Items = settingsManager.FilamentDictionary.GenerateColors(FilamentSpool.TypeEnum.NoFilament).Cast <object>().ToList <object>(); color_combobox.ListBox.Items.Sort(); color_combobox.Select = 0; }
private void CreateAdvancedFrame(GUIHost host) { var interfaceframeAdvanced = Resources.interfaceframe_advanced; advancedFrame = new XMLFrame(); advancedFrame.Init(host, interfaceframeAdvanced, new ButtonCallback(AdvancedFrameButtonCallback)); advancedFrame.ID = 1003; advancedFrame.CenterHorizontallyInParent = true; advancedFrame.RelativeY = 0.1f; advancedFrame.RelativeWidth = 0.95f; advancedFrame.RelativeHeight = 0.9f; advancedFrame.BGColor = new Color4(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue); advancedFrame.Visible = false; advancedFrame.Enabled = false; childFrame.AddChildElement(advancedFrame); advancedFrame.Refresh(); softwareupdate_options = (ComboBoxWidget)advancedFrame.FindChildElement(303); updateSoftware_button = (ButtonWidget)advancedFrame.FindChildElement(305); download_progress = (SpriteAnimationWidget)advancedFrame.FindChildElement(306); update_text = (TextWidget)advancedFrame.FindChildElement(304); softwareupdate_options.TextChangedCallback = new ComboBoxWidget.ComboBoxTextChangedCallback(AdvancedSettingsComboBoxCallback); softwareupdate_options.AddItem(Locale.GlobalLocale.T("T_UpdateOp_DownloadInstall")); softwareupdate_options.AddItem(Locale.GlobalLocale.T("T_UpdateOp_DownloadNoInstall")); softwareupdate_options.AddItem(Locale.GlobalLocale.T("T_UpdateOp_TakeNoAction")); softwareupdate_options.Select = softwareUpdater.UpdaterMode != Updater.UpdateSettings.DownloadNotInstall ? (softwareUpdater.UpdaterMode != Updater.UpdateSettings.NoAction ? 0 : 2) : 1; update_text.Visible = false; download_progress.Visible = false; updateSoftware_button.Enabled = true; updateSoftware_button.Visible = false; advancedFrame.DoOnUpdate = new ElementStandardDelegate(AdvancedSettingsOnUpdate); useMultipleModelsCheckbox = (ButtonWidget)advancedFrame.FindChildElement(313); showRemoveModelWarningCheckbox = (ButtonWidget)advancedFrame.FindChildElement(315); autoDetectUnitsCheckbox = (ButtonWidget)advancedFrame.FindChildElement(317); }
private void comboBoxChangedCallBack(ComboBoxWidget combobox) { var tag = combobox.tag; SlicerSettingsItem smartSlicerSetting = smartSlicerSettings[tag]; smartSlicerSetting.ParseUserValue(combobox.Value.ToString()); ProcessValidity(tag, smartSlicerSetting, combobox); }
public void AdvancedSettingsComboBoxCallback(ComboBoxWidget box) { if (!initialized || box.ID != 303) { return; } settings.CurrentAppearanceSettings.UpdaterMode = !(box.Text == Locale.GlobalLocale.T("T_UpdateOp_TakeNoAction")) ? (!(box.Text == Locale.GlobalLocale.T("T_UpdateOp_DownloadNoInstall")) ? Updater.UpdateSettings.DownloadInstall : Updater.UpdateSettings.DownloadNotInstall) : Updater.UpdateSettings.NoAction; SaveSettings(); }
private void CreateAppearanceFrame(GUIHost host) { var interfaceframeAppearance = Resources.interfaceframe_appearance; appearanceFrame = new XMLFrame(); appearanceFrame.Init(host, interfaceframeAppearance, new ButtonCallback(AppearanceFrameButtonCallback)); appearanceFrame.ID = 1001; appearanceFrame.CenterHorizontallyInParent = true; appearanceFrame.RelativeY = 0.1f; appearanceFrame.RelativeWidth = 0.95f; appearanceFrame.RelativeHeight = 0.9f; appearanceFrame.BGColor = new Color4(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue); appearanceFrame.Visible = true; appearanceFrame.Enabled = true; printercolorCombobox = (ComboBoxWidget)appearanceFrame.FindChildElement(104); printercolorCombobox.Select = 0; printercolorCombobox.TextChangedCallback = new ComboBoxWidget.ComboBoxTextChangedCallback(ColorComboboxChanged); modelcolorCombobox = (ComboBoxWidget)appearanceFrame.FindChildElement(106); modelcolorCombobox.Select = 0; modelcolorCombobox.TextChangedCallback = new ComboBoxWidget.ComboBoxTextChangedCallback(ColorComboboxChanged); iconcolorCombobox = (ComboBoxWidget)appearanceFrame.FindChildElement(108); iconcolorCombobox.Select = 0; iconcolorCombobox.TextChangedCallback = new ComboBoxWidget.ComboBoxTextChangedCallback(ColorComboboxChanged); var childElement = (TextWidget)appearanceFrame.FindChildElement(100); mm_button = (ButtonWidget)appearanceFrame.FindChildElement(101); inches_button = (ButtonWidget)appearanceFrame.FindChildElement(102); pro_button = (ButtonWidget)appearanceFrame.FindChildElement(110); m1_button = (ButtonWidget)appearanceFrame.FindChildElement(111); rendermode_combobox = (ComboBoxWidget)appearanceFrame.FindChildElement(207); rendermode_combobox.TextChangedCallback = new ComboBoxWidget.ComboBoxTextChangedCallback(RenderModeChanged); switch (OpenGLRendererObject.openGLRenderMode) { case OpenGLRendererObject.OpenGLRenderMode.VBOs: rendermode_combobox.Select = 0; break; case OpenGLRendererObject.OpenGLRenderMode.ARBVBOs: rendermode_combobox.Select = 1; break; case OpenGLRendererObject.OpenGLRenderMode.ImmediateMode: rendermode_combobox.Select = 1; break; } childFrame.AddChildElement(appearanceFrame); appearanceFrame.Refresh(); }
private void RenderModeChanged(ComboBoxWidget combobox) { if (!initialized) { return; } var itemIndex = combobox.GetItemIndex(combobox.EditBox.Text); if (itemIndex < 0) { return; } var str = (string)combobox.ListBox.Items[itemIndex]; if (!(str == "Enhanced Graphics Mode")) { if (!(str == "ARB Vertex Buffer Objects")) { if (!(str == "Basic Graphics Mode")) { return; } OpenGLRendererObject.openGLRenderMode = OpenGLRendererObject.OpenGLRenderMode.ImmediateMode; } else { OpenGLRendererObject.openGLRenderMode = OpenGLRendererObject.OpenGLRenderMode.ARBVBOs; } } else { OpenGLRendererObject.openGLRenderMode = OpenGLRendererObject.OpenGLRenderMode.VBOs; } }
private void ColorComboboxChanged(ComboBoxWidget combobox) { if (!initialized) { return; } if (combobox.ID == 104) { settings.CurrentAppearanceSettings.PrinterColor = printercolorCombobox.Text; } if (combobox.ID == 106) { settings.CurrentAppearanceSettings.ModelColor = modelcolorCombobox.Text; } if (combobox.ID != 108) { return; } settings.CurrentAppearanceSettings.IconColor = iconcolorCombobox.Text; }
public void OnKeyboardEvent(KeyboardEvent keyboardevent) { if (keyboardevent.Tab) { var tabIndexElements = new List <Element2D>(); m_oframeRootMasterElement.GetNextTabIndexElement(ref tabIndexElements); var num1 = -1; foreach (Element2D element2D in tabIndexElements) { if (element2D.tabIndex > num1) { num1 = element2D.tabIndex; } } var num2 = -1; var element2D1 = (Element2D)null; if (m_oeFocusElement != null) { element2D1 = m_oeFocusElement; num2 = m_oeFocusElement.tabIndex; } var num3 = -1; foreach (Element2D element2D2 in tabIndexElements) { if (element2D2.tabIndex != num2) { if (element2D2.tabIndex < num2) { if (num1 - num2 + element2D2.tabIndex < num3 || num3 == -1) { m_oeFocusElement = element2D2; num3 = num1 - num2 + element2D2.tabIndex; } } else if (element2D2.tabIndex - num2 < num3 || num3 == -1) { m_oeFocusElement = element2D2; num3 = element2D2.tabIndex - num2; } } } if (element2D1 != null) { element2D1.HasFocus = false; } if (m_ocbComboboxSelected != null) { m_ocbComboboxSelected.ShowDropDown = false; } m_oeFocusElement.HasFocus = true; if (m_oeFocusElement.GetElementType() == ElementType.ComboBoxWidget) { m_ocbComboboxSelected = (ComboBoxWidget)m_oeFocusElement; } else { m_ocbComboboxSelected = null; } } else if (keyboardevent.Type == KeyboardEventType.CommandKey && ((CommandKeyEvent)keyboardevent).Key == KeyboardCommandKey.Escape) { m_oframeRootMasterElement.OnKeyboardEvent(keyboardevent); } else if (m_oeFocusElement != null) { if (m_ocbComboboxSelected != null) { m_ocbComboboxSelected.OnKeyboardEvent(keyboardevent); } else if (m_oeFocusElement.IsListBoxElement()) { ListBoxWidget listBoxElement = m_oeFocusElement.GetListBoxElement(); if (listBoxElement == null) { return; } listBoxElement.HasFocus = true; listBoxElement.OnKeyboardEvent(keyboardevent); listBoxElement.HasFocus = false; } else { m_oeFocusElement.OnKeyboardEvent(keyboardevent); } } else { m_oframeRootMasterElement.OnKeyboardEvent(keyboardevent); } }
public bool OnMouseCommand(MouseEvent mouseevent) { var flag = false; if (mouseevent.type == MouseEventType.Leave) { m_oframeRootMasterElement.OnMouseLeave(); return(false); } tooltipFrame.Hide(); m_oeMouseOverElement = m_oframeRootControlElement.GetSelfOrDependantAtPoint(mouseevent.pos.x, mouseevent.pos.y); if (m_oeMouseOverElement == null) { if (m_oeFocusElement != null && m_oeFocusElement.Visible && m_oeFocusElement.Enabled) { m_oeMouseOverElement = m_oeFocusElement.GetSelfOrDependantAtPoint(mouseevent.pos.x, mouseevent.pos.y); } if (m_oeMouseOverElement == null) { m_oeMouseOverElement = m_oframeRootMasterElement.GetSelfOrDependantAtPoint(mouseevent.pos.x, mouseevent.pos.y); } } if (m_oeSelectedElement != null && m_oeSelectedElement != m_oeMouseOverElement) { flag = m_oeSelectedElement.OnMouseCommand(mouseevent); m_oeSelectedElement = null; } Element2D mouseOverElement = m_oeMouseOverElement; if (mouseOverElement != null) { m_oeSelectedElement = mouseOverElement; flag = mouseOverElement.OnMouseCommand(mouseevent); if (mouseOverElement.GetElementType() != ElementType.Frame && mouseOverElement.GetElementType() != ElementType.ScrollFrame) { if (mouseevent.type == MouseEventType.Down) { if (m_oeSelectedElement.IsComboBoxElement()) { if (m_ocbComboboxSelected != null && m_ocbComboboxSelected != m_oeSelectedElement.GetComboBoxElement()) { m_ocbComboboxSelected.ShowDropDown = false; m_ocbComboboxSelected.HasFocus = false; } m_ocbComboboxSelected = m_oeSelectedElement.GetComboBoxElement(); } else if (m_ocbComboboxSelected != null) { m_ocbComboboxSelected.ShowDropDown = false; m_ocbComboboxSelected = null; } if (m_oeFocusElement != null && m_oeFocusElement != mouseOverElement && m_oeFocusElement != m_ocbComboboxSelected) { m_oeFocusElement.HasFocus = false; } m_oeFocusElement = mouseOverElement; m_oeFocusElement.HasFocus = true; if (m_ocbComboboxSelected != null) { m_ocbComboboxSelected.HasFocus = true; } } else if (mouseevent.type == MouseEventType.Up && mouseevent.button == MouseButton.Right) { var elementType = (int)m_oeMouseOverElement.GetElementType(); } } if (mouseevent.type == MouseEventType.MouseWheel) { if (m_oeSelectedElement.IsListBoxElement()) { ListBoxWidget listBoxElement = m_oeSelectedElement.GetListBoxElement(); if (listBoxElement != null) { if (mouseevent.delta > 0) { listBoxElement.ScrollBar.MoveSlider(-1f); } else { listBoxElement.ScrollBar.MoveSlider(1f); } } } else if (m_oeSelectedElement.IsScrollFrame()) { m_oeSelectedElement.GetScrollFrame()?.OnMouseCommand(mouseevent); } } } else if (GlobalChildDialog.Count > 0 && mouseevent.type == MouseEventType.Down) { Element2D element2D = GlobalChildDialog.Last(); if (element2D is Frame) { ((Frame)element2D).Close(); } } if (mouseevent.type == MouseEventType.Up) { m_oframeRootMasterElement.OnMouseLeave(); if (m_ocbComboboxSelected != null && m_oeSelectedElement == null) { m_ocbComboboxSelected.ShowDropDown = false; } } m_oframeRootMasterElement.OnMouseMove(mouseevent.pos.x, mouseevent.pos.y); m_smePrevMouseEvent = mouseevent; return(flag); }
public void Init(GUIHost host) { this.host = host; Init(host, "guicontrols", 640f, 320f, 704f, 383f, 41, 8, 64, 35, 8, 64); Sprite.pixel_perfect = false; var textWidget1 = new TextWidget(0); textWidget1.SetPosition(50, 2); textWidget1.SetSize(500, 35); textWidget1.Text = "Add Filament Profile"; textWidget1.Alignment = QFontAlignment.Left; textWidget1.Size = FontSize.Medium; textWidget1.Color = new Color4(0.5f, 0.5f, 0.5f, 1f); AddChildElement(textWidget1); var textWidget2 = new TextWidget(0) { Text = "Type", Size = FontSize.Medium, Alignment = QFontAlignment.Left }; textWidget2.SetPosition(30, 50); textWidget2.SetSize(200, 24); textWidget2.Color = new Color4(0.5f, 0.5f, 0.5f, 1f); AddChildElement(textWidget2); var textWidget3 = new TextWidget(0) { Text = "Color", Size = FontSize.Medium, Alignment = QFontAlignment.Left }; textWidget3.SetPosition(30, 110); textWidget3.SetSize(50, 24); textWidget3.Color = new Color4(0.5f, 0.5f, 0.5f, 1f); textWidget3.IgnoreMouse = true; AddChildElement(textWidget3); type_combobox = new ComboBoxWidget(0); type_combobox.Init(host); type_combobox.ListBox.SetOnChangeCallback(new ListBoxWidget.OnChangeCallback(MyOnChangeFilamentTypeCallback)); type_combobox.Select = 0; type_combobox.SetPosition(30, 80); type_combobox.SetSize(256, 24); foreach (FilamentSpool.TypeEnum typeEnum in (FilamentSpool.TypeEnum[])Enum.GetValues(typeof(FilamentSpool.TypeEnum))) { type_combobox.AddItem(typeEnum.ToString()); } type_combobox.Select = 0; type_combobox.tabIndex = 1; AddChildElement(type_combobox); color_combobox = new ComboBoxWidget(0); color_combobox.Init(host); color_combobox.ListBox.SetOnChangeCallback(new ListBoxWidget.OnChangeCallback(MyOnChangeColorCallback)); color_combobox.Select = 0; color_combobox.SetPosition(30, 140); color_combobox.SetSize(256, 24); color_combobox.tabIndex = 2; AddChildElement(color_combobox); AddColorItems(FilamentSpool.TypeEnum.ABS); add_button = new ButtonWidget(3); add_button.Init(host, "guicontrols", 896f, 192f, 959f, byte.MaxValue, 896f, 256f, 959f, 319f, 896f, 320f, 959f, 383f, 960f, 128f, 1023f, 191f); add_button.Size = FontSize.Medium; add_button.Text = "Add"; add_button.SetGrowableWidth(4, 4, 32); add_button.SetGrowableHeight(4, 4, 32); add_button.SetSize(80, 32); add_button.SetPosition(70, -50); add_button.SetCallback(new ButtonCallback(MyButtonCallback)); add_button.tabIndex = 4; AddChildElement(add_button); cancel_button = new ButtonWidget(4); cancel_button.Init(host, "guicontrols", 896f, 192f, 959f, byte.MaxValue, 896f, 256f, 959f, 319f, 896f, 320f, 959f, 383f, 960f, 128f, 1023f, 191f); cancel_button.Size = FontSize.Medium; cancel_button.Text = "Cancel"; cancel_button.SetGrowableWidth(4, 4, 32); cancel_button.SetGrowableHeight(4, 4, 32); cancel_button.SetSize(100, 32); cancel_button.SetPosition(160, -50); cancel_button.SetCallback(new ButtonCallback(MyButtonCallback)); cancel_button.tabIndex = 5; AddChildElement(cancel_button); Sprite.pixel_perfect = false; }
static void Main(string[] args) { PDFNet.Initialize(); // Relative path to the folder containing test files. // string input_path = "../../TestFiles/"; string output_path = "../../TestFiles/Output/"; // The vector used to store the name and count of all fields. // This is used later on to clone the fields Dictionary <string, int> field_names = new Dictionary <string, int>(); //---------------------------------------------------------------------------------- // Example 1: Programatically create new Form Fields and Widget Annotations. //---------------------------------------------------------------------------------- try { using (PDFDoc doc = new PDFDoc()) { // Create a blank new page and add some form fields. Page blank_page = doc.PageCreate(); // Text Widget Creation // Create an empty text widget with black text. TextWidget text1 = TextWidget.Create(doc, new Rect(110, 700, 380, 730)); text1.SetText("Basic Text Field"); text1.RefreshAppearance(); blank_page.AnnotPushBack(text1); // Create a vertical text widget with blue text and a yellow background. TextWidget text2 = TextWidget.Create(doc, new Rect(50, 400, 90, 730)); text2.SetRotation(90); // Set the text content. text2.SetText(" ****Lucky Stars!****"); // Set the font type, text color, font size, border color and background color. text2.SetFont(Font.Create(doc, Font.StandardType1Font.e_helvetica_oblique)); text2.SetFontSize(28); text2.SetTextColor(new ColorPt(0, 0, 1), 3); text2.SetBorderColor(new ColorPt(0, 0, 0), 3); text2.SetBackgroundColor(new ColorPt(1, 1, 0), 3); text2.RefreshAppearance(); // Add the annotation to the page. blank_page.AnnotPushBack(text2); // Create two new text widget with Field names employee.name.first and employee.name.last // This logic shows how these widgets can be created using either a field name string or // a Field object TextWidget text3 = TextWidget.Create(doc, new Rect(110, 660, 380, 690), "employee.name.first"); text3.SetText("Levi"); text3.SetFont(Font.Create(doc, Font.StandardType1Font.e_times_bold)); text3.RefreshAppearance(); blank_page.AnnotPushBack(text3); Field emp_last_name = doc.FieldCreate("employee.name.last", Field.Type.e_text, "Ackerman"); TextWidget text4 = TextWidget.Create(doc, new Rect(110, 620, 380, 650), emp_last_name); text4.SetFont(Font.Create(doc, Font.StandardType1Font.e_times_bold)); text4.RefreshAppearance(); blank_page.AnnotPushBack(text4); // Signature Widget Creation (unsigned) SignatureWidget signature1 = SignatureWidget.Create(doc, new Rect(110, 560, 260, 610)); signature1.RefreshAppearance(); blank_page.AnnotPushBack(signature1); // CheckBox Widget Creation // Create a check box widget that is not checked. CheckBoxWidget check1 = CheckBoxWidget.Create(doc, new Rect(140, 490, 170, 520)); check1.RefreshAppearance(); blank_page.AnnotPushBack(check1); // Create a check box widget that is checked. CheckBoxWidget check2 = CheckBoxWidget.Create(doc, new Rect(190, 490, 250, 540), "employee.name.check1"); check2.SetBackgroundColor(new ColorPt(1, 1, 1), 3); check2.SetBorderColor(new ColorPt(0, 0, 0), 3); // Check the widget (by default it is unchecked). check2.SetChecked(true); check2.RefreshAppearance(); blank_page.AnnotPushBack(check2); // PushButton Widget Creation PushButtonWidget pushbutton1 = PushButtonWidget.Create(doc, new Rect(380, 490, 520, 540)); pushbutton1.SetTextColor(new ColorPt(1, 1, 1), 3); pushbutton1.SetFontSize(36); pushbutton1.SetBackgroundColor(new ColorPt(0, 0, 0), 3); // Add a caption for the pushbutton. pushbutton1.SetStaticCaptionText("PushButton"); pushbutton1.RefreshAppearance(); blank_page.AnnotPushBack(pushbutton1); // ComboBox Widget Creation ComboBoxWidget combo1 = ComboBoxWidget.Create(doc, new Rect(280, 560, 580, 610)); // Add options to the combobox widget. combo1.AddOption("Combo Box No.1"); combo1.AddOption("Combo Box No.2"); combo1.AddOption("Combo Box No.3"); // Make one of the options in the combo box selected by default. combo1.SetSelectedOption("Combo Box No.2"); combo1.SetTextColor(new ColorPt(1, 0, 0), 3); combo1.SetFontSize(28); combo1.RefreshAppearance(); blank_page.AnnotPushBack(combo1); // ListBox Widget Creation ListBoxWidget list1 = ListBoxWidget.Create(doc, new Rect(400, 620, 580, 730)); // Add one option to the listbox widget. list1.AddOption("List Box No.1"); // Add multiple options to the listbox widget in a batch. string[] list_options = new string[2] { "List Box No.2", "List Box No.3" }; list1.AddOptions(list_options); // Select some of the options in list box as default options list1.SetSelectedOptions(list_options); // Enable list box to have multi-select when editing. list1.GetField().SetFlag(Field.Flag.e_multiselect, true); list1.SetFont(Font.Create(doc, Font.StandardType1Font.e_times_italic)); list1.SetTextColor(new ColorPt(1, 0, 0), 3); list1.SetFontSize(28); list1.SetBackgroundColor(new ColorPt(1, 1, 1), 3); list1.RefreshAppearance(); blank_page.AnnotPushBack(list1); // RadioButton Widget Creation // Create a radio button group and add three radio buttons in it. RadioButtonGroup radio_group = RadioButtonGroup.Create(doc, "RadioGroup"); RadioButtonWidget radiobutton1 = radio_group.Add(new Rect(140, 410, 190, 460)); radiobutton1.SetBackgroundColor(new ColorPt(1, 1, 0), 3); radiobutton1.RefreshAppearance(); RadioButtonWidget radiobutton2 = radio_group.Add(new Rect(310, 410, 360, 460)); radiobutton2.SetBackgroundColor(new ColorPt(0, 1, 0), 3); radiobutton2.RefreshAppearance(); RadioButtonWidget radiobutton3 = radio_group.Add(new Rect(480, 410, 530, 460)); // Enable the third radio button. By default the first one is selected radiobutton3.EnableButton(); radiobutton3.SetBackgroundColor(new ColorPt(0, 1, 1), 3); radiobutton3.RefreshAppearance(); radio_group.AddGroupButtonsToPage(blank_page); // Custom push button annotation creation PushButtonWidget custom_pushbutton1 = PushButtonWidget.Create(doc, new Rect(260, 320, 360, 360)); // Set the annotation appearance. custom_pushbutton1.SetAppearance(CreateCustomButtonAppearance(doc, false), Annot.AnnotationState.e_normal); // Create 'SubmitForm' action. The action will be linked to the button. FileSpec url = FileSpec.CreateURL(doc, "http://www.pdftron.com"); pdftron.PDF.Action button_action = pdftron.PDF.Action.CreateSubmitForm(url); // Associate the above action with 'Down' event in annotations action dictionary. Obj annot_action = custom_pushbutton1.GetSDFObj().PutDict("AA"); annot_action.Put("D", button_action.GetSDFObj()); blank_page.AnnotPushBack(custom_pushbutton1); // Add the page as the last page in the document. doc.PagePushBack(blank_page); // If you are not satisfied with the look of default auto-generated appearance // streams you can delete "AP" entry from the Widget annotation and set // "NeedAppearances" flag in AcroForm dictionary: // doc.GetAcroForm().PutBool("NeedAppearances", true); // This will force the viewer application to auto-generate new appearance streams // every time the document is opened. // // Alternatively you can generate custom annotation appearance using ElementWriter // and then set the "AP" entry in the widget dictionary to the new appearance // stream. // // Yet another option is to pre-populate field entries with dummy text. When // you edit the field values using PDFNet the new field appearances will match // the old ones. doc.RefreshFieldAppearances(); doc.Save(output_path + "forms_test1.pdf", 0); Console.WriteLine("Done."); } } catch (PDFNetException e) { Console.WriteLine(e.Message); } //---------------------------------------------------------------------------------- // Example 2: // Fill-in forms / Modify values of existing fields. // Traverse all form fields in the document (and print out their names). // Search for specific fields in the document. //---------------------------------------------------------------------------------- try { using (PDFDoc doc = new PDFDoc(output_path + "forms_test1.pdf")) { doc.InitSecurityHandler(); FieldIterator itr; for (itr = doc.GetFieldIterator(); itr.HasNext(); itr.Next()) { Field field = itr.Current(); string cur_field_name = field.GetName(); // Add one to the count for this field name for later processing field_names[cur_field_name] = (field_names.ContainsKey(cur_field_name) ? field_names[cur_field_name] + 1 : 1); Console.WriteLine("Field name: {0}", field.GetName()); Console.WriteLine("Field partial name: {0}", field.GetPartialName()); string str_val = field.GetValueAsString(); Console.Write("Field type: "); Field.Type type = field.GetType(); switch (type) { case Field.Type.e_button: Console.WriteLine("Button"); break; case Field.Type.e_radio: Console.WriteLine("Radio button: Value = " + str_val); break; case Field.Type.e_check: field.SetValue(true); Console.WriteLine("Check box: Value = " + str_val); break; case Field.Type.e_text: { Console.WriteLine("Text"); // Edit all variable text in the document String old_value = "none"; if (field.GetValue() != null) { old_value = field.GetValue().GetAsPDFText(); } field.SetValue("This is a new value. The old one was: " + old_value); } break; case Field.Type.e_choice: Console.WriteLine("Choice"); break; case Field.Type.e_signature: Console.WriteLine("Signature"); break; } Console.WriteLine("------------------------------"); } // Search for a specific field Field fld = doc.GetField("employee.name.first"); if (fld != null) { Console.WriteLine("Field search for {0} was successful", fld.GetName()); } else { Console.WriteLine("Field search failed."); } // Regenerate field appearances. doc.RefreshFieldAppearances(); doc.Save(output_path + "forms_test_edit.pdf", 0); Console.WriteLine("Done."); } } catch (PDFNetException e) { Console.WriteLine(e.Message); } //---------------------------------------------------------------------------------- // Sample: Form templating // Replicate pages and form data within a document. Then rename field names to make // them unique. //---------------------------------------------------------------------------------- try { // Sample: Copying the page with forms within the same document using (PDFDoc doc = new PDFDoc(output_path + "forms_test1.pdf")) { doc.InitSecurityHandler(); Page src_page = doc.GetPage(1); doc.PagePushBack(src_page); // Append several copies of the second page doc.PagePushBack(src_page); // Note that forms are successfully copied doc.PagePushBack(src_page); doc.PagePushBack(src_page); // Now we rename fields in order to make every field unique. // You can use this technique for dynamic template filling where you have a 'master' // form page that should be replicated, but with unique field names on every page. foreach (KeyValuePair <string, int> cur_field in field_names) { RenameAllFields(doc, cur_field.Key, cur_field.Value); } doc.Save(output_path + "forms_test1_cloned.pdf", 0); Console.WriteLine("Done."); } } catch (PDFNetException e) { Console.WriteLine(e.Message); } //---------------------------------------------------------------------------------- // Sample: // Flatten all form fields in a document. // Note that this sample is intended to show that it is possible to flatten // individual fields. PDFNet provides a utility function PDFDoc.FlattenAnnotations() // that will automatically flatten all fields. //---------------------------------------------------------------------------------- try { using (PDFDoc doc = new PDFDoc(output_path + "forms_test1.pdf")) { doc.InitSecurityHandler(); bool auto = true; if (auto) { doc.FlattenAnnotations(); } else // Manual flattening { // Traverse all pages PageIterator pitr = doc.GetPageIterator(); for (; pitr.HasNext(); pitr.Next()) { Page page = pitr.Current(); for (int i = page.GetNumAnnots() - 1; i >= 0; --i) { Annot annot = page.GetAnnot(i); if (annot.GetType() == Annot.Type.e_Widget) { annot.Flatten(page); } } } } doc.Save(output_path + "forms_test1_flattened.pdf", 0); Console.WriteLine("Done."); } } catch (PDFNetException e) { Console.WriteLine(e.Message); } }