private Widget CreateWidgetForQuestion(QuestionStatement statement, GuiEnvironment environment, WidgetStyle style) { Widget questionWidget; switch (statement.Type) { case BooleanValueType _: questionWidget = new CheckBoxWidget(new BooleanValue(false), statement, environment, style); break; case DateValueType _: questionWidget = new DatePickerWidget(new DateValue(DateTime.Now), statement, environment, style); break; case StringValueType _: questionWidget = new TextFieldWidget(new StringValue(string.Empty), statement, environment, style); break; case DecimalValueType _: questionWidget = new ValidatedTextFieldWidget(new DecimalValue(0), new DecimalValidator(), statement, environment, style); break; case IntegerValueType _: questionWidget = new ValidatedTextFieldWidget(new IntegerValue(0), new IntegerValidator(), statement, environment, style); break; case MoneyValueType _: questionWidget = new ValidatedTextFieldWidget(new MoneyValue(0), new MoneyValidator(), statement, environment, style); break; default: throw new ArgumentOutOfRangeException(nameof(statement.Type)); } return(questionWidget); }
public virtual TResult Visit(CheckBoxWidget expression, TEnvironment environment) { return(default(TResult)); }
public void Start() { SessionData sessionData = SessionData.GetInstance(); // Create the root widget group m_rootWidgetGroup = new WidgetGroup(null, gamePanelStyle.Width, gamePanelStyle.Height, 0.0f, 0.0f); m_rootWidgetGroup.SetWidgetEventListener(this); // Background for the game info ImageWidget gamePanel = new ImageWidget( m_rootWidgetGroup, gamePanelStyle.Width, gamePanelStyle.Height, gamePanelStyle.Background, 0.0f, 0.0f); float statsLabelWidth = (gamePanel.Width - 2 * BORDER_WIDTH) / 2 - 3; float statsX = 10; float statsY = 10; // Owner Name LabelWidget ownerNameLabel = new LabelWidget(m_rootWidgetGroup, statsLabelWidth, STATS_LABEL_HEIGHT, statsX, statsY, "Owner Name:"); ownerNameLabel.Alignment = TextAnchor.UpperRight; m_ownerNameLabel = new LabelWidget( m_rootWidgetGroup, statsLabelWidth, STATS_LABEL_HEIGHT, statsX + statsLabelWidth, statsY, sessionData.UserName); m_ownerNameLabel.Text = ""; // Game name statsY += STATS_LABEL_HEIGHT; LabelWidget gameNameLabel = new LabelWidget(m_rootWidgetGroup, statsLabelWidth, STATS_LABEL_HEIGHT, statsX, statsY, "Game Name:"); gameNameLabel.Alignment = TextAnchor.UpperRight; m_gameNameTextField = new TextEntryWidget(m_rootWidgetGroup, statsLabelWidth, STATS_LABEL_HEIGHT, statsX + statsLabelWidth, statsY, ""); // IRC Server statsY += STATS_LABEL_HEIGHT; LabelWidget IRCServerLabel = new LabelWidget(m_rootWidgetGroup, statsLabelWidth, STATS_LABEL_HEIGHT, statsX, statsY, "IRC Server:"); IRCServerLabel.Alignment = TextAnchor.UpperRight; m_IRCServerTextField = new TextEntryWidget(m_rootWidgetGroup, statsLabelWidth, STATS_LABEL_HEIGHT, statsX + statsLabelWidth, statsY, ""); m_IRCServerTextField.Text = ServerConstants.DEFAULT_IRC_SERVER; // IRC Port statsY += STATS_LABEL_HEIGHT; LabelWidget IRCPortLabel = new LabelWidget(m_rootWidgetGroup, statsLabelWidth, STATS_LABEL_HEIGHT, statsX, statsY, "IRC Port:"); IRCPortLabel.Alignment = TextAnchor.UpperRight; m_IRCPortTextField = new TextEntryWidget(m_rootWidgetGroup, statsLabelWidth, STATS_LABEL_HEIGHT, statsX + statsLabelWidth, statsY, ""); m_IRCPortTextField.Restrict = @"[^0-9]"; m_IRCPortTextField.MaxLength = 6; m_IRCPortTextField.Text = ServerConstants.DEFAULT_IRC_PORT.ToString(); // IRC Enabled statsY += STATS_LABEL_HEIGHT; LabelWidget IRCEnabledLabel = new LabelWidget(m_rootWidgetGroup, statsLabelWidth, STATS_LABEL_HEIGHT, statsX, statsY, "IRC Enabled:"); IRCEnabledLabel.Alignment = TextAnchor.UpperRight; m_IRCEnabledToggle = new CheckBoxWidget(m_rootWidgetGroup, chekBoxStyle, statsX + statsLabelWidth, statsY); m_IRCEnabledToggle.Enabled = true; // IRC Encryption Enabled statsY += STATS_LABEL_HEIGHT; LabelWidget IRCEncryptionEnabledLabel = new LabelWidget(m_rootWidgetGroup, statsLabelWidth, STATS_LABEL_HEIGHT, statsX, statsY, "IRC Encryption Enabled:"); IRCEncryptionEnabledLabel.Alignment = TextAnchor.UpperRight; m_IRCEncryptionEnabledToggle = new CheckBoxWidget(m_rootWidgetGroup, chekBoxStyle, statsX + statsLabelWidth, statsY); m_IRCEncryptionEnabledToggle.Enabled = true; // Creation status m_statusLabel = new LabelWidget(m_rootWidgetGroup, gamePanel.Width, STATS_LABEL_HEIGHT, 0.0f, 0.0f, ""); m_statusLabel.SetLocalPosition(0, gamePanel.Height - m_statusLabel.Height - BORDER_WIDTH); m_statusLabel.Alignment = TextAnchor.UpperCenter; // Create button m_createButton = new ButtonWidget(m_rootWidgetGroup, buttonStyle, 0, 0, "Create"); m_createButton.SetLocalPosition(gamePanel.Width / 3 - m_createButton.Width / 2, m_statusLabel.LocalY - m_createButton.Height - 5); // Cancel button m_cancelButton = new ButtonWidget(m_rootWidgetGroup, buttonStyle, 0, 0, "Cancel"); m_cancelButton.SetLocalPosition((2 * gamePanel.Width) / 3 - m_cancelButton.Width / 2, m_statusLabel.LocalY - m_cancelButton.Height - 5); // Center the group info widgets m_rootWidgetGroup.SetLocalPosition(Screen.width / 2 - gamePanel.Width / 2, Screen.height / 2 - gamePanel.Height / 2); }
public void Start() { bool isLocalServerRunning = AsyncRPGServer.GetInstance().IsServerActive(); Screen.showCursor = true; // Create the root widget group m_rootWidgetGroup = new WidgetGroup(null, Screen.width, Screen.height, 0.0f, 0.0f); m_rootWidgetGroup.SetWidgetEventListener(this); m_widgetEventDispatcher = new WidgetEventDispatcher(); m_widgetEventDispatcher.Start(m_rootWidgetGroup); // Create the widget group to hold the login panel m_loginPanelWidgetGroup = new WidgetGroup( m_rootWidgetGroup, loginPanelStyle.gamePanelStyle.Width, loginPanelStyle.gamePanelStyle.Height, Screen.width / 2 - loginPanelStyle.gamePanelStyle.Width / 2, Screen.height / 2 - loginPanelStyle.gamePanelStyle.Height / 2); // Background for the game info new ImageWidget( m_loginPanelWidgetGroup, loginPanelStyle.gamePanelStyle.Width, loginPanelStyle.gamePanelStyle.Height, loginPanelStyle.gamePanelStyle.Background, 0.0f, 0.0f); // Username and Password - Left Aligned { WidgetLayoutCursor cursor = new WidgetLayoutCursor( loginPanelStyle.gamePanelStyle.BorderWidth + loginPanelStyle.gamePanelStyle.WidgetSpacing, loginPanelStyle.gamePanelStyle.BorderWidth + loginPanelStyle.gamePanelStyle.WidgetSpacing); cursor.Kerning = loginPanelStyle.gamePanelStyle.WidgetSpacing; cursor.Leading = loginPanelStyle.gamePanelStyle.WidgetSpacing; // Server cursor.Advance( new LabelWidget( m_loginPanelWidgetGroup, loginPanelStyle.labelStyle, cursor.X, cursor.Y, "Server:")); m_serverText = cursor.Advance( new TextEntryWidget( m_loginPanelWidgetGroup, loginPanelStyle.textEntryStyle, cursor.X, cursor.Y, "localhost")); m_serverText.Visible = !isLocalServerRunning; m_localHostLabel = new LabelWidget( m_loginPanelWidgetGroup, m_serverText.Width, m_serverText.Height, m_serverText.LocalX, m_serverText.LocalY, "localhost"); m_localHostLabel.Visible = isLocalServerRunning; cursor.NewLine(); // Local hosted check box cursor.Advance( new LabelWidget( m_loginPanelWidgetGroup, loginPanelStyle.labelStyle, cursor.X, cursor.Y, "Host Server:")); m_localHostCheckBox = cursor.Advance( new CheckBoxWidget( m_loginPanelWidgetGroup, loginPanelStyle.checkBoxStyle, cursor.X, cursor.Y)); m_localHostCheckBox.Enabled = isLocalServerRunning; cursor.NewLine(); // Username cursor.Advance( new LabelWidget( m_loginPanelWidgetGroup, loginPanelStyle.labelStyle, cursor.X, cursor.Y, "Username:"******"test" : "")); cursor.NewLine(); // Password cursor.Advance( new LabelWidget( m_loginPanelWidgetGroup, loginPanelStyle.labelStyle, cursor.X, cursor.Y, "Password:"******"password" : "")); m_passwordText.IsPassword = true; cursor.NewLine(); } // Buttons - Centered along the bottom { WidgetLayoutCursor cursor = new WidgetLayoutCursor( loginPanelStyle.gamePanelStyle.Width / 2 - loginPanelStyle.gamePanelStyle.WidgetSpacing / 2 - loginPanelStyle.buttonStyle.Width, loginPanelStyle.gamePanelStyle.Height - loginPanelStyle.buttonStyle.Height - loginPanelStyle.labelStyle.Height - loginPanelStyle.gamePanelStyle.BorderWidth - loginPanelStyle.gamePanelStyle.WidgetSpacing); m_createAccountButton = cursor.Advance( new ButtonWidget( m_loginPanelWidgetGroup, loginPanelStyle.buttonStyle, cursor.X, cursor.Y, "New Account")); m_createAccountButton.Visible = false; m_loginButton = cursor.Advance( new ButtonWidget( m_loginPanelWidgetGroup, loginPanelStyle.buttonStyle, cursor.X, cursor.Y, "Login")); m_loginButton.Visible = true; cursor.NewLine(); m_loginStatusLabel = cursor.Advance( new LabelWidget( m_loginPanelWidgetGroup, loginPanelStyle.gamePanelStyle.Width - 2.0f * loginPanelStyle.gamePanelStyle.BorderWidth, loginPanelStyle.labelStyle.Height, cursor.X, cursor.Y, "")); } // Server Status Panel m_serverPanelWidgetGroup = new WidgetGroup( m_rootWidgetGroup, loginPanelStyle.gamePanelStyle.Width, loginPanelStyle.gamePanelStyle.Height, Screen.width / 2 - loginPanelStyle.gamePanelStyle.Width / 2, Screen.height / 2 - loginPanelStyle.gamePanelStyle.Height / 2); m_serverPanelWidgetGroup.Visible = false; // Background for the game info new ImageWidget( m_serverPanelWidgetGroup, loginPanelStyle.gamePanelStyle.Width, loginPanelStyle.gamePanelStyle.Height, loginPanelStyle.gamePanelStyle.Background, 0.0f, 0.0f); { float contentCenter = loginPanelStyle.gamePanelStyle.Width / 2.0f; WidgetLayoutCursor cursor = new WidgetLayoutCursor( 0.0f, loginPanelStyle.gamePanelStyle.BorderWidth + loginPanelStyle.gamePanelStyle.WidgetSpacing); cursor.Kerning = loginPanelStyle.gamePanelStyle.WidgetSpacing; cursor.Leading = loginPanelStyle.gamePanelStyle.WidgetSpacing; LabelWidget topLabel = cursor.Advance( new LabelWidget( m_serverPanelWidgetGroup, loginPanelStyle.labelStyle, contentCenter - loginPanelStyle.labelStyle.Width / 2.0f, cursor.Y, "[Server]")); topLabel.Alignment = TextAnchor.UpperCenter; cursor.NewLine(); m_serverStatusText = cursor.Advance( new ScrollTextWidget( m_serverPanelWidgetGroup, loginPanelStyle.scrollTextStyle, contentCenter - loginPanelStyle.scrollTextStyle.Width / 2.0f, cursor.Y, "")); cursor.NewLine(); m_serverOkButton = cursor.Advance( new ButtonWidget( m_serverPanelWidgetGroup, loginPanelStyle.buttonStyle, contentCenter - loginPanelStyle.buttonStyle.Width / 2.0f, cursor.Y, "Ok")); m_serverOkButton.Visible = false; } }
public void Start() { SessionData sessionData = SessionData.GetInstance(); // Create the root widget group m_rootWidgetGroup = new WidgetGroup(null, gamePanelStyle.Width, gamePanelStyle.Height, 0.0f, 0.0f); m_rootWidgetGroup.SetWidgetEventListener(this); // Background for the game info ImageWidget gamePanel = new ImageWidget( m_rootWidgetGroup, gamePanelStyle.Width, gamePanelStyle.Height, gamePanelStyle.Background, 0.0f, 0.0f); float statsLabelWidth = (gamePanel.Width - 2 * BORDER_WIDTH) / 2 - 3; float statsX = 10; float statsY = 10; // Owner Name LabelWidget ownerNameLabel = new LabelWidget(m_rootWidgetGroup, statsLabelWidth, STATS_LABEL_HEIGHT, statsX, statsY, "Owner Name:"); ownerNameLabel.Alignment = TextAnchor.UpperRight; m_ownerNameLabel = new LabelWidget( m_rootWidgetGroup, statsLabelWidth, STATS_LABEL_HEIGHT, statsX + statsLabelWidth, statsY, sessionData.UserName); m_ownerNameLabel.Text = ""; // Game name statsY += STATS_LABEL_HEIGHT; LabelWidget gameNameLabel = new LabelWidget(m_rootWidgetGroup, statsLabelWidth, STATS_LABEL_HEIGHT, statsX, statsY, "Game Name:"); gameNameLabel.Alignment = TextAnchor.UpperRight; m_gameNameTextField = new TextEntryWidget(m_rootWidgetGroup, statsLabelWidth, STATS_LABEL_HEIGHT, statsX+statsLabelWidth, statsY, ""); // IRC Server statsY += STATS_LABEL_HEIGHT; LabelWidget IRCServerLabel = new LabelWidget(m_rootWidgetGroup, statsLabelWidth, STATS_LABEL_HEIGHT, statsX, statsY, "IRC Server:"); IRCServerLabel.Alignment = TextAnchor.UpperRight; m_IRCServerTextField = new TextEntryWidget(m_rootWidgetGroup, statsLabelWidth, STATS_LABEL_HEIGHT, statsX+statsLabelWidth, statsY, ""); m_IRCServerTextField.Text = ServerConstants.DEFAULT_IRC_SERVER; // IRC Port statsY += STATS_LABEL_HEIGHT; LabelWidget IRCPortLabel = new LabelWidget(m_rootWidgetGroup, statsLabelWidth, STATS_LABEL_HEIGHT, statsX, statsY, "IRC Port:"); IRCPortLabel.Alignment = TextAnchor.UpperRight; m_IRCPortTextField = new TextEntryWidget(m_rootWidgetGroup, statsLabelWidth, STATS_LABEL_HEIGHT, statsX + statsLabelWidth, statsY, ""); m_IRCPortTextField.Restrict = @"[^0-9]"; m_IRCPortTextField.MaxLength = 6; m_IRCPortTextField.Text = ServerConstants.DEFAULT_IRC_PORT.ToString(); // IRC Enabled statsY += STATS_LABEL_HEIGHT; LabelWidget IRCEnabledLabel = new LabelWidget(m_rootWidgetGroup, statsLabelWidth, STATS_LABEL_HEIGHT, statsX, statsY, "IRC Enabled:"); IRCEnabledLabel.Alignment = TextAnchor.UpperRight; m_IRCEnabledToggle = new CheckBoxWidget(m_rootWidgetGroup, chekBoxStyle, statsX + statsLabelWidth, statsY); m_IRCEnabledToggle.Enabled = true; // IRC Encryption Enabled statsY += STATS_LABEL_HEIGHT; LabelWidget IRCEncryptionEnabledLabel = new LabelWidget(m_rootWidgetGroup, statsLabelWidth, STATS_LABEL_HEIGHT, statsX, statsY, "IRC Encryption Enabled:"); IRCEncryptionEnabledLabel.Alignment = TextAnchor.UpperRight; m_IRCEncryptionEnabledToggle = new CheckBoxWidget(m_rootWidgetGroup, chekBoxStyle, statsX + statsLabelWidth, statsY); m_IRCEncryptionEnabledToggle.Enabled = true; // Creation status m_statusLabel = new LabelWidget(m_rootWidgetGroup, gamePanel.Width, STATS_LABEL_HEIGHT, 0.0f, 0.0f, ""); m_statusLabel.SetLocalPosition(0, gamePanel.Height - m_statusLabel.Height - BORDER_WIDTH); m_statusLabel.Alignment = TextAnchor.UpperCenter; // Create button m_createButton = new ButtonWidget(m_rootWidgetGroup, buttonStyle, 0, 0, "Create"); m_createButton.SetLocalPosition(gamePanel.Width/3 - m_createButton.Width/2, m_statusLabel.LocalY - m_createButton.Height - 5); // Cancel button m_cancelButton = new ButtonWidget(m_rootWidgetGroup, buttonStyle, 0, 0, "Cancel"); m_cancelButton.SetLocalPosition((2*gamePanel.Width)/3 - m_cancelButton.Width/2, m_statusLabel.LocalY - m_cancelButton.Height - 5); // Center the group info widgets m_rootWidgetGroup.SetLocalPosition(Screen.width / 2 - gamePanel.Width / 2, Screen.height / 2 - gamePanel.Height / 2); }
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); } }
public void Start() { bool isLocalServerRunning= AsyncRPGServer.GetInstance().IsServerActive(); Screen.showCursor = true; // Create the root widget group m_rootWidgetGroup = new WidgetGroup(null, Screen.width, Screen.height, 0.0f, 0.0f); m_rootWidgetGroup.SetWidgetEventListener(this); m_widgetEventDispatcher = new WidgetEventDispatcher(); m_widgetEventDispatcher.Start(m_rootWidgetGroup); // Create the widget group to hold the login panel m_loginPanelWidgetGroup = new WidgetGroup( m_rootWidgetGroup, loginPanelStyle.gamePanelStyle.Width, loginPanelStyle.gamePanelStyle.Height, Screen.width / 2 - loginPanelStyle.gamePanelStyle.Width / 2, Screen.height / 2 - loginPanelStyle.gamePanelStyle.Height / 2); // Background for the game info new ImageWidget( m_loginPanelWidgetGroup, loginPanelStyle.gamePanelStyle.Width, loginPanelStyle.gamePanelStyle.Height, loginPanelStyle.gamePanelStyle.Background, 0.0f, 0.0f); // Username and Password - Left Aligned { WidgetLayoutCursor cursor = new WidgetLayoutCursor( loginPanelStyle.gamePanelStyle.BorderWidth + loginPanelStyle.gamePanelStyle.WidgetSpacing, loginPanelStyle.gamePanelStyle.BorderWidth + loginPanelStyle.gamePanelStyle.WidgetSpacing); cursor.Kerning= loginPanelStyle.gamePanelStyle.WidgetSpacing; cursor.Leading= loginPanelStyle.gamePanelStyle.WidgetSpacing; // Server cursor.Advance( new LabelWidget( m_loginPanelWidgetGroup, loginPanelStyle.labelStyle, cursor.X, cursor.Y, "Server:")); m_serverText = cursor.Advance( new TextEntryWidget( m_loginPanelWidgetGroup, loginPanelStyle.textEntryStyle, cursor.X, cursor.Y, "localhost")); m_serverText.Visible= !isLocalServerRunning; m_localHostLabel= new LabelWidget( m_loginPanelWidgetGroup, m_serverText.Width, m_serverText.Height, m_serverText.LocalX, m_serverText.LocalY, "localhost"); m_localHostLabel.Visible= isLocalServerRunning; cursor.NewLine(); // Local hosted check box cursor.Advance( new LabelWidget( m_loginPanelWidgetGroup, loginPanelStyle.labelStyle, cursor.X, cursor.Y, "Host Server:")); m_localHostCheckBox= cursor.Advance( new CheckBoxWidget( m_loginPanelWidgetGroup, loginPanelStyle.checkBoxStyle, cursor.X, cursor.Y)); m_localHostCheckBox.Enabled = isLocalServerRunning; cursor.NewLine(); // Username cursor.Advance( new LabelWidget( m_loginPanelWidgetGroup, loginPanelStyle.labelStyle, cursor.X, cursor.Y, "Username:"******"test" : "")); cursor.NewLine(); // Password cursor.Advance( new LabelWidget( m_loginPanelWidgetGroup, loginPanelStyle.labelStyle, cursor.X, cursor.Y, "Password:"******"password" : "")); m_passwordText.IsPassword= true; cursor.NewLine(); } // Buttons - Centered along the bottom { WidgetLayoutCursor cursor = new WidgetLayoutCursor( loginPanelStyle.gamePanelStyle.Width/2 - loginPanelStyle.gamePanelStyle.WidgetSpacing/2 - loginPanelStyle.buttonStyle.Width, loginPanelStyle.gamePanelStyle.Height - loginPanelStyle.buttonStyle.Height - loginPanelStyle.labelStyle.Height - loginPanelStyle.gamePanelStyle.BorderWidth - loginPanelStyle.gamePanelStyle.WidgetSpacing); m_createAccountButton = cursor.Advance( new ButtonWidget( m_loginPanelWidgetGroup, loginPanelStyle.buttonStyle, cursor.X, cursor.Y, "New Account")); m_createAccountButton.Visible= false; m_loginButton = cursor.Advance( new ButtonWidget( m_loginPanelWidgetGroup, loginPanelStyle.buttonStyle, cursor.X, cursor.Y, "Login")); m_loginButton.Visible= true; cursor.NewLine(); m_loginStatusLabel= cursor.Advance( new LabelWidget( m_loginPanelWidgetGroup, loginPanelStyle.gamePanelStyle.Width - 2.0f*loginPanelStyle.gamePanelStyle.BorderWidth, loginPanelStyle.labelStyle.Height, cursor.X, cursor.Y, "")); } // Server Status Panel m_serverPanelWidgetGroup = new WidgetGroup( m_rootWidgetGroup, loginPanelStyle.gamePanelStyle.Width, loginPanelStyle.gamePanelStyle.Height, Screen.width / 2 - loginPanelStyle.gamePanelStyle.Width / 2, Screen.height / 2 - loginPanelStyle.gamePanelStyle.Height / 2); m_serverPanelWidgetGroup.Visible= false; // Background for the game info new ImageWidget( m_serverPanelWidgetGroup, loginPanelStyle.gamePanelStyle.Width, loginPanelStyle.gamePanelStyle.Height, loginPanelStyle.gamePanelStyle.Background, 0.0f, 0.0f); { float contentCenter= loginPanelStyle.gamePanelStyle.Width / 2.0f; WidgetLayoutCursor cursor = new WidgetLayoutCursor( 0.0f, loginPanelStyle.gamePanelStyle.BorderWidth + loginPanelStyle.gamePanelStyle.WidgetSpacing); cursor.Kerning= loginPanelStyle.gamePanelStyle.WidgetSpacing; cursor.Leading= loginPanelStyle.gamePanelStyle.WidgetSpacing; LabelWidget topLabel= cursor.Advance( new LabelWidget( m_serverPanelWidgetGroup, loginPanelStyle.labelStyle, contentCenter - loginPanelStyle.labelStyle.Width / 2.0f, cursor.Y, "[Server]")); topLabel.Alignment= TextAnchor.UpperCenter; cursor.NewLine(); m_serverStatusText= cursor.Advance( new ScrollTextWidget( m_serverPanelWidgetGroup, loginPanelStyle.scrollTextStyle, contentCenter - loginPanelStyle.scrollTextStyle.Width / 2.0f, cursor.Y, "")); cursor.NewLine(); m_serverOkButton= cursor.Advance( new ButtonWidget( m_serverPanelWidgetGroup, loginPanelStyle.buttonStyle, contentCenter - loginPanelStyle.buttonStyle.Width / 2.0f, cursor.Y, "Ok")); m_serverOkButton.Visible= false; } }