public static void Run() { try { // ExStart:CreateDoc // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Forms(); // Create a new document Document doc = new Document(); Page page = doc.Pages.Add(); // Add radio button field RadioButtonField field = new RadioButtonField(page); field.Rect = new Aspose.Pdf.Rectangle(40, 650, 100, 720); field.PartialName = "NewField"; // Add radio button options. please note that these options are situated // Neither horizontally nor vertically. // You can try to set any coordinates (and even size) for them. RadioButtonOptionField opt1 = new RadioButtonOptionField(); opt1.Rect = new Aspose.Pdf.Rectangle(40, 650, 60, 670); opt1.OptionName = "Item1"; opt1.Border = new Border(opt1); opt1.Border.Width = 1; opt1.Characteristics.Border = System.Drawing.Color.Black; RadioButtonOptionField opt2 = new RadioButtonOptionField(); opt2.Rect = new Aspose.Pdf.Rectangle(60, 670, 80, 690); opt2.OptionName = "Item2"; opt2.Border = new Border(opt2); opt2.Border.Width = 1; opt2.Characteristics.Border = System.Drawing.Color.Black; RadioButtonOptionField opt3 = new RadioButtonOptionField(); opt3.Rect = new Aspose.Pdf.Rectangle(80, 690, 100, 710); opt3.OptionName = "Item3"; opt3.Border = new Border(opt3); opt3.Border.Width = 1; opt3.Characteristics.Border = System.Drawing.Color.Black; field.Add(opt1); field.Add(opt2); field.Add(opt3); doc.Form.Add(field); dataDir = dataDir + "CreateDoc_out.pdf"; // Save the PDF document doc.Save(dataDir); // ExEnd:CreateDoc Console.WriteLine("\nNew doc with 3 items radio button created successfully.\nFile saved at " + dataDir); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public static void Run() { try { // ExStart:GroupedCheckBoxes // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Forms(); // Instantiate Document object Document pdfDocument = new Document(); // Add a page to PDF file Page page = pdfDocument.Pages.Add(); // Instatiate RadioButtonField object with page number as argument RadioButtonField radio = new RadioButtonField(pdfDocument.Pages[1]); // Add first radio button option and also specify its origin using Rectangle object RadioButtonOptionField opt1 = new RadioButtonOptionField(page, new Aspose.Pdf.Rectangle(0, 0, 20, 20)); RadioButtonOptionField opt2 = new RadioButtonOptionField(page, new Aspose.Pdf.Rectangle(100, 0, 120, 20)); opt1.OptionName = "Test1"; opt2.OptionName = "Test2"; radio.Add(opt1); radio.Add(opt2); opt1.Style = BoxStyle.Square; opt2.Style = BoxStyle.Square; opt1.Style = BoxStyle.Cross; opt2.Style = BoxStyle.Cross; opt1.Border = new Border(opt1); opt1.Border.Style = BorderStyle.Solid; opt1.Border.Width = 1; opt1.Characteristics.Border = System.Drawing.Color.Black; opt2.Border = new Border(opt2); opt2.Border.Width = 1; opt2.Border.Style = BorderStyle.Solid; opt2.Characteristics.Border = System.Drawing.Color.Black; // Add radio button to form object of Document object pdfDocument.Form.Add(radio); dataDir = dataDir + "GroupedCheckBoxes_out_.pdf"; // Save the PDF document pdfDocument.Save(dataDir); // ExEnd:GroupedCheckBoxes Console.WriteLine("\nGrouped checkboxes added successfully.\nFile saved at " + dataDir); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public static void Run() { try { // ExStart:GroupedCheckBoxes // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Forms(); // Instantiate Document object Document pdfDocument = new Document(); // Add a page to PDF file Page page = pdfDocument.Pages.Add(); // Instatiate RadioButtonField object with page number as argument RadioButtonField radio = new RadioButtonField(pdfDocument.Pages[1]); // Add first radio button option and also specify its origin using Rectangle object RadioButtonOptionField opt1 = new RadioButtonOptionField(page, new Aspose.Pdf.Rectangle(0, 0, 20, 20)); RadioButtonOptionField opt2 = new RadioButtonOptionField(page, new Aspose.Pdf.Rectangle(100, 0, 120, 20)); opt1.OptionName = "Test1"; opt2.OptionName = "Test2"; radio.Add(opt1); radio.Add(opt2); opt1.Style = BoxStyle.Square; opt2.Style = BoxStyle.Square; opt1.Style = BoxStyle.Cross; opt2.Style = BoxStyle.Cross; opt1.Border = new Border(opt1); opt1.Border.Style = BorderStyle.Solid; opt1.Border.Width = 1; opt1.Characteristics.Border = System.Drawing.Color.Black; opt2.Border = new Border(opt2); opt2.Border.Width = 1; opt2.Border.Style = BorderStyle.Solid; opt2.Characteristics.Border = System.Drawing.Color.Black; // Add radio button to form object of Document object pdfDocument.Form.Add(radio); dataDir = dataDir + "GroupedCheckBoxes_out.pdf"; // Save the PDF document pdfDocument.Save(dataDir); // ExEnd:GroupedCheckBoxes Console.WriteLine("\nGrouped checkboxes added successfully.\nFile saved at " + dataDir); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public static void Run() { try { // ExStart:RadioButtonWithOptions // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Forms(); Document doc = new Document(); Page page = doc.Pages.Add(); Aspose.Pdf.Table table = new Aspose.Pdf.Table(); table.ColumnWidths = "120 120 120"; page.Paragraphs.Add(table); Row r1 = table.Rows.Add(); Cell c1 = r1.Cells.Add(); Cell c2 = r1.Cells.Add(); Cell c3 = r1.Cells.Add(); RadioButtonField rf = new RadioButtonField(page); rf.PartialName = "radio"; doc.Form.Add(rf, 1); RadioButtonOptionField opt1 = new RadioButtonOptionField(); RadioButtonOptionField opt2 = new RadioButtonOptionField(); RadioButtonOptionField opt3 = new RadioButtonOptionField(); opt1.OptionName = "Item1"; opt2.OptionName = "Item2"; opt3.OptionName = "Item3"; opt1.Width = 15; opt1.Height = 15; opt2.Width = 15; opt2.Height = 15; opt3.Width = 15; opt3.Height = 15; rf.Add(opt1); rf.Add(opt2); rf.Add(opt3); opt1.Border = new Border(opt1); opt1.Border.Width = 1; opt1.Border.Style = BorderStyle.Solid; opt1.Characteristics.Border = System.Drawing.Color.Black; opt1.DefaultAppearance.TextColor = System.Drawing.Color.Red; opt1.Caption = new TextFragment("Item1"); opt2.Border = new Border(opt1); opt2.Border.Width = 1; opt2.Border.Style = BorderStyle.Solid; opt2.Characteristics.Border = System.Drawing.Color.Black; opt2.DefaultAppearance.TextColor = System.Drawing.Color.Red; opt2.Caption = new TextFragment("Item2"); opt3.Border = new Border(opt1); opt3.Border.Width = 1; opt3.Border.Style = BorderStyle.Solid; opt3.Characteristics.Border = System.Drawing.Color.Black; opt3.DefaultAppearance.TextColor = System.Drawing.Color.Red; opt3.Caption = new TextFragment("Item3"); c1.Paragraphs.Add(opt1); c2.Paragraphs.Add(opt2); c3.Paragraphs.Add(opt3); dataDir = dataDir + "RadioButtonWithOptions_out.pdf"; // Save the PDF file doc.Save(dataDir); // ExEnd:RadioButtonWithOptions Console.WriteLine("\nRadio button field with three options added successfully.\nFile saved at " + dataDir); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private Aspose.Pdf.Forms.Field getFormField(HNodeTag inputNode) { Aspose.Pdf.Forms.Field field = null; string fieldType = inputNode.GetAttribute("type", "text"); //button|checkbox|file|hidden|image|password|radio|reset|submit|text switch (fieldType) { case "button": case "submit": field = getFormField_Button(); break; case "checkbox": field = getFormField_CheckBox(); break; case "file": case "hidden": case "image": case "password": case "reset": break; case "radio": field = getFormField_RadioBox(); break; case "text": default: field = getFormField_TextBox(); break; } return(field); Aspose.Pdf.Forms.Field getFormField_TextBox() { TextBoxField textBoxField = new TextBoxField(); textBoxField.Height = 16; textBoxField.Width = 160; string name = inputNode.GetAttribute("name", "text_box_field"); textBoxField.PartialName = name; string value = inputNode.GetAttribute("value", ""); if (!String.IsNullOrEmpty(value)) { textBoxField.Value = value; } //Так делать нельзя, падает исключение при pdfDocument.ProcessParagraphs(); //textBoxField.Value = ""; //Border border = new Border(field); //border.Width = 1; //border.Dash = new Dash(1, 1); //field.Border = border; return(textBoxField); } Aspose.Pdf.Forms.Field getFormField_CheckBox() { CheckboxField checkBoxField = new CheckboxField(); checkBoxField.Height = 10; checkBoxField.Width = 10; string name = inputNode.GetAttribute("name", "checkbox_field"); checkBoxField.PartialName = name; //Так делать нельзя, падает исключение при pdfDocument.ProcessParagraphs(); //checkBoxField.Checked = true; return(checkBoxField); } Aspose.Pdf.Forms.Field getFormField_RadioBox() { string name = inputNode.GetAttribute("name", "radio_button_field"); RadioButtonField rbf = getRadioButtonField(name); RadioButtonOptionField opt = new RadioButtonOptionField(); opt.OptionName = name + "_" + (rbf.Count + 1).ToString(); opt.Width = 12; opt.Height = 12; //Так делать нельзя, падает исключение при pdfDocument.ProcessParagraphs(); //opt.Border = new Border(opt); //opt.Border.Width = 1; //opt.Border.Style = BorderStyle.Solid; //opt.Characteristics.Border = System.Drawing.Color.Black; //opt.DefaultAppearance.TextColor = System.Drawing.Color.Red; //opt.Caption = new TextFragment("Item1"); rbf.Add(opt); return(opt); } Aspose.Pdf.Forms.Field getFormField_Button() { ButtonField buttonField = new ButtonField(); string value = inputNode.GetAttribute("value", ""); buttonField.Height = 18; buttonField.Width = 12 + 6 * value.Length; if (!String.IsNullOrEmpty(value)) { buttonField.Value = value; } return(buttonField); } }