public static void Run() { // ExStart:PreserveRights // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Forms(); // Read the source PDF form with FileAccess of Read and Write. // We need ReadWrite permission because after modification, // we need to save the updated contents in same document/file. FileStream fs = new FileStream(dataDir + "input.pdf", FileMode.Open, FileAccess.ReadWrite); // Instantiate Document instance Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(fs); // Get values from all fields foreach (Field formField in pdfDocument.Form) { // If the fullname of field contains A1, perform the operation if (formField.FullName.Contains("A1")) { // Cast form field as TextBox TextBoxField textBoxField = formField as TextBoxField; // Modify field value textBoxField.Value = "Testing"; } } // Save the updated document in save FileStream pdfDocument.Save(); // Close the File Stream object fs.Close(); // ExEnd:PreserveRights }
public static void Run() { // ExStart:AddTextBoxField // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Forms(); // Open document Document pdfDocument = new Document(dataDir + "TextField.pdf"); // Create a field TextBoxField textBoxField = new TextBoxField(pdfDocument.Pages[1], new Aspose.Pdf.Rectangle(100, 200, 300, 300)); textBoxField.PartialName = "textbox1"; textBoxField.Value = "Text Box"; // TextBoxField.Border = new Border( Border border = new Border(textBoxField); border.Width = 5; border.Dash = new Dash(1, 1); textBoxField.Border = border; textBoxField.Color = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Green); // Add field to the document pdfDocument.Form.Add(textBoxField, 1); dataDir = dataDir + "TextBox_out.pdf"; // Save modified PDF pdfDocument.Save(dataDir); // ExEnd:AddTextBoxField Console.WriteLine("\nTextbox field added successfully.\nFile saved at " + dataDir); }
public TagBuilder HtmlText() { TagBuilder tb = new TagBuilder("div"); if (type == RowType.Header) { tb.AddCssClass("HeadCell"); TagBuilder tbHeaderLabel = new TagBuilder("HeaderLabel"); tbHeaderLabel.InnerHtml.AppendHtml(HtmlLabel); TagBuilder tbHeaderSearch = new TagBuilder("HeaderSearch"); TextBoxField t = new TextBoxField("TODO-NameId", "TableTextBoxHeader AutoComplete", "", "..."); tbHeaderSearch.AddCssClass("HeaderSrchCl"); tbHeaderSearch.InnerHtml.AppendHtml(t.BuildHtmlTag()); tb.InnerHtml.AppendHtml(tbHeaderLabel); tb.InnerHtml.AppendHtml(tbHeaderSearch); } else if (type == RowType.Data) { tb.AddCssClass("Cell"); tb.InnerHtml.AppendHtml(CellField.BuildBaseHtmlTag()); } else { throw new NotImplementedException(); } return(tb); }
public static void Run() { // ExStart:SetJavaScript // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Forms(); // Load input PDF file Document doc = new Document(dataDir + "SetJavaScript.pdf"); TextBoxField field = (TextBoxField)doc.Form["textbox1"]; // 2 digits after point // No separator // Neg style = minus // No currency field.Actions.OnModifyCharacter = new JavascriptAction("AFNumber_Keystroke(2, 1, 1, 0, \"\", true)"); field.Actions.OnFormat = new JavascriptAction("AFNumber_Format(2, 1, 1, 0, \"\", true)"); // Set initial field value field.Value = "123"; dataDir = dataDir + "Restricted_out.pdf"; // Save resultant PDF doc.Save(dataDir); // ExEnd:SetJavaScript Console.WriteLine("\nJavaScript on form field setup successfully.\nFile saved at " + dataDir); }
public static void Main(string[] args) { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); //Open document Document pdfDocument = new Document(dataDir + "input.pdf"); //Create a field TextBoxField textBoxField = new TextBoxField(pdfDocument.Pages[1], new Aspose.Pdf.Rectangle(100, 200, 300, 300)); textBoxField.PartialName = "textbox1"; textBoxField.Value = "Text Box"; //textBoxField.Border = new Border( Border border = new Border(textBoxField); border.Width = 5; border.Dash = new Dash(1, 1); textBoxField.Border = border; textBoxField.Color = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Green); //Add field to the document pdfDocument.Form.Add(textBoxField, 1); //Save modified PDF pdfDocument.Save(dataDir + "output.pdf"); }
private static void CreateFields(RadFixedDocument document) { CheckBoxField check = new CheckBoxField("checkBox"); document.AcroForm.FormFields.Add(check); check.IsChecked = true; ComboBoxField combo = new ComboBoxField("combo"); document.AcroForm.FormFields.Add(combo); combo.Options.Add(new ChoiceOption("Combo choice 1")); combo.Options.Add(new ChoiceOption("Combo choice 2")); combo.Options.Add(new ChoiceOption("Combo choice 3")); combo.Options.Add(new ChoiceOption("Combo choice 4")); combo.Options.Add(new ChoiceOption("Combo choice 5")); combo.Value = combo.Options[2]; CombTextBoxField comb = new CombTextBoxField("comb"); document.AcroForm.FormFields.Add(comb); comb.MaxLengthOfInputCharacters = 10; comb.Value = "0123456789"; ListBoxField list = new ListBoxField("list"); document.AcroForm.FormFields.Add(list); list.AllowMultiSelection = true; list.Options.Add(new ChoiceOption("List choice 1")); list.Options.Add(new ChoiceOption("List choice 2")); list.Options.Add(new ChoiceOption("List choice 3")); list.Options.Add(new ChoiceOption("List choice 4")); list.Options.Add(new ChoiceOption("List choice 5")); list.Options.Add(new ChoiceOption("List choice 6")); list.Options.Add(new ChoiceOption("List choice 7")); list.Value = new ChoiceOption[] { list.Options[0], list.Options[2] }; PushButtonField push = new PushButtonField("push"); document.AcroForm.FormFields.Add(push); RadioButtonField radio = new RadioButtonField("radio"); document.AcroForm.FormFields.Add(radio); radio.Options.Add(new RadioOption("Radio option 1")); radio.Options.Add(new RadioOption("Radio option 2")); radio.Value = radio.Options[1]; SignatureField signature = new SignatureField("signiture"); document.AcroForm.FormFields.Add(signature); TextBoxField textBox = new TextBoxField("textBox"); document.AcroForm.FormFields.Add(textBox); textBox.Value = "Sample text..."; }
public void AddField(double ulx, double uly, double width, double height, double winW, double winH, string text, string label, double fontSize, int pageIndex) { var pageW = PdfDoc.Pages[pageIndex].Rect.Width; var pageH = PdfDoc.Pages[pageIndex].Rect.Height; var scaleW = pageW / winW; var scaleH = pageH / winH; ulx = ulx * scaleW; uly = uly * scaleH; width = width * scaleW; height = height * scaleH; fontSize = fontSize * scaleW; var urx = ulx + width; var lly = pageH - (uly + height); var ury = pageH - uly; var marginH = 2 * scaleH; var marginW = 2 * scaleW; // Create a field var textBoxField = new TextBoxField(PdfDoc.Pages[pageIndex], new Rectangle(ulx, lly, urx, ury)) { PartialName = label, Value = text, Color = Color.Transparent, DefaultAppearance = { FontSize = fontSize } , Margin = new MarginInfo(marginW, marginH, marginW, marginH) , Characteristics = { Border = System.Drawing.Color.Transparent } , Name = label , }; var border = new Border(textBoxField) { Width = 1, Style = BorderStyle.Solid }; textBoxField.Border = border; // Add field to the document PdfDoc.Form.Add(textBoxField, pageIndex); }
protected override void EditFormReset() { base.EditFormReset(); TextBoxField field = (EditForm.Fields[0] as TextBoxField); if (field != null) { field.DefaultText = string.Empty; field.ReadOnly = false; } EditForm_ShowDetails(false); UserChecked = false; InvitedUsersPanel.Visible = true; }
public static void Main(string[] args) { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); //open document Document pdfDocument = new Document(dataDir + "input.pdf"); //get a field TextBoxField textBoxField = pdfDocument.Form["textbox1"] as TextBoxField; //get field value Console.WriteLine("PartialName : {0} ", textBoxField.PartialName); Console.WriteLine("Value : {0} ", textBoxField.Value); }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Forms(); //open document Document pdfDocument = new Document(dataDir + "GetValueFromField.pdf"); //get a field TextBoxField textBoxField = pdfDocument.Form["textbox1"] as TextBoxField; //get field value Console.WriteLine("PartialName : {0} ", textBoxField.PartialName); Console.WriteLine("Value : {0} ", textBoxField.Value); }
public static void Main(string[] args) { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); //open document Document pdfDocument = new Document(dataDir + "input.pdf"); //get a field TextBoxField textBoxField = pdfDocument.Form["textbox1"] as TextBoxField; //modify field value textBoxField.Value = "Value to be filled in the field"; //save updated document pdfDocument.Save(dataDir + "output.pdf"); }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Forms(); //open document Document pdfDocument = new Document(dataDir + "FillFormField.pdf"); //get a field TextBoxField textBoxField = pdfDocument.Form["textbox1"] as TextBoxField; //modify field value textBoxField.Value = "Value to be filled in the field"; //save updated document pdfDocument.Save(dataDir + "FillFormField_out.pdf"); }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Forms(); //open document Document pdfDocument = new Document(dataDir + "MoveFormField.pdf"); //get a field TextBoxField textBoxField = pdfDocument.Form["textbox1"] as TextBoxField; //modify field location textBoxField.Rect = new Aspose.Pdf.Rectangle(300, 400, 600, 500); //save modified document pdfDocument.Save(dataDir + "MoveFormField_out.pdf"); }
public static void Main(string[] args) { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); //open document Document pdfDocument = new Document(dataDir + "input.pdf"); //get a field TextBoxField textBoxField = pdfDocument.Form["textbox1"] as TextBoxField; //modify field location textBoxField.Rect = new Aspose.Pdf.Rectangle(300, 400, 600, 500); //save modified document pdfDocument.Save(dataDir + "output.pdf"); }
/// <summary> /// Converts from the FoundOPS model to the API model /// </summary> /// <param name="fieldModel">The FoundOPS model of a TextBoxField to be converted</param> /// <returns>A TextBoxField that has been converted to it's API model</returns> public static TextBoxField ConvertModel(Core.Models.CoreEntities.TextBoxField fieldModel) { var field = new TextBoxField { Id = fieldModel.Id, CreatedDate = fieldModel.CreatedDate, Name = fieldModel.Name, Required = fieldModel.Required, ToolTip = fieldModel.Tooltip, ParentFieldId = fieldModel.ParentFieldId, ServiceTemplateId = fieldModel.ServiceTemplateId, IsMultiLine = fieldModel.IsMultiline, Value = fieldModel.Value }; field.SetLastModified(fieldModel.LastModified, fieldModel.LastModifyingUserId); return field; }
private TableRow SetDataLabelsRow(int r, DataRow dr) { TableRow tr = new TableRow(); Field f; for (int c = 0; c < dr.ItemArray.Length; c++) { if (Columns[c].ReadOnly) { f = new LabelField(dr.ItemArray[c].ToString().Trim()); } else { f = new TextBoxField(ID + "-r" + r + "c" + c, "dbfieldid", "DGCellTB", dr.ItemArray[c].ToString().Trim()); } tr.AddColumnCell(f); } return(tr); }
/// <summary> /// Converts the API model back to the FoundOPS model /// </summary> /// <param name="textBoxField"></param> /// <returns></returns> public static Core.Models.CoreEntities.TextBoxField ConvertBack(TextBoxField textBoxField) { var field = new Core.Models.CoreEntities.TextBoxField { Id = textBoxField.Id, Name = textBoxField.Name, Required = textBoxField.Required, Tooltip = textBoxField.ToolTip, ParentFieldId = textBoxField.ParentFieldId, ServiceTemplateId = textBoxField.ServiceTemplateId, IsMultiline = textBoxField.IsMultiLine, Value = textBoxField.Value, CreatedDate = textBoxField.CreatedDate, LastModified = textBoxField.LastModified, LastModifyingUserId = textBoxField.LastModifyingUserId }; return field; }
public static void Run() { // ExStart:FillFormField // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Forms(); // Open document Document pdfDocument = new Document(dataDir + "FillFormField.pdf"); // Get a field TextBoxField textBoxField = pdfDocument.Form["textbox1"] as TextBoxField; // Modify field value textBoxField.Value = "Value to be filled in the field"; dataDir = dataDir + "FillFormField_out.pdf"; // Save updated document pdfDocument.Save(dataDir); // ExEnd:FillFormField Console.WriteLine("\nForm field filled successfully.\nFile saved at " + dataDir); }
public void PutTextBoxFieldTest() { const string name = "FormDataTextBox.pdf"; UploadFile(name, name); var textBox = new TextBoxField(PageIndex: 1, IsGroup: false) { Color = new Color(255, 255, 0, 0), Multiline = false, MaxLen = 100, Rect = new Rectangle(35, 650, 290, 600), Value = "Value!\nValue", PartialName = "testField", }; var response = PdfApi.PutTextBoxField(name, "Petitioner", textBox, folder: TempFolder); Assert.That(response.Code, Is.EqualTo(200)); }
private static TextBoxField CreateTextBoxField(Page page, string name) { var textBoxField = new TextBoxField(page, new Rectangle(100, 200, 300, 400)) { Name = name, PartialName = name, MappingName = name, AlternateName = name + 1 }; var border = new Aspose.Pdf.InteractiveFeatures.Annotations.Border(textBoxField) { Width = 5, Dash = new Aspose.Pdf.InteractiveFeatures.Annotations.Dash(1, 1) }; textBoxField.Border = border; textBoxField.Value = ""; return(textBoxField); }
public static void Run() { // ExStart:MoveFormField // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Forms(); // Open document Document pdfDocument = new Document(dataDir + "MoveFormField.pdf"); // Get a field TextBoxField textBoxField = pdfDocument.Form["textbox1"] as TextBoxField; // Modify field location textBoxField.Rect = new Aspose.Pdf.Rectangle(300, 400, 600, 500); dataDir = dataDir + "MoveFormField_out_.pdf"; // Save modified document pdfDocument.Save(dataDir); // ExEnd:MoveFormField Console.WriteLine("\nForm field moved successfully to a new location.\nFile saved at " + dataDir); }
public static void Run() { // ExStart:ArabicTextFilling // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Forms(); // Load PDF form contents FileStream fs = new FileStream(dataDir + "FillFormField.pdf", FileMode.Open, FileAccess.ReadWrite); // Instantiate Document instance with stream holding form file Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(fs); // Get referecne of particuarl TextBoxField TextBoxField txtFld = pdfDocument.Form["textbox1"] as TextBoxField; // Fill form field with arabic text txtFld.Value = "يولد جميع الناس أحراراً متساوين في"; dataDir = dataDir + "ArabicTextFilling_out_.pdf"; // Save updated document pdfDocument.Save(dataDir); // ExEnd:ArabicTextFilling Console.WriteLine("\nArabic text filled successfully in form field.\nFile saved at " + dataDir); }
private Field CreateFieldFromSourceData(int r, int c) { string CellID = ID + "-r" + r + "c" + c; Field f = new Field("", "", "", ""); if (Columns[c].ReadOnly) { if (Columns[c].Type == ColumnType.CheckBox) { f = new CheckBoxField("", CellID, "", SourceData.Rows[r].ItemArray[c].ToString().Trim() == "TRUE" ? true : false, false); } else { f = new LabelField(SourceData.Rows[r].ItemArray[c].ToString().Trim()); } } else { switch (Columns[c].Type) { case ColumnType.Unknown: case ColumnType.Text: f = new TextBoxField(CellID, "dbfieldid", "DGCellTB", SourceData.Rows[r].ItemArray[c].ToString().Trim()); break; case ColumnType.CheckBox: f = new CheckBoxField("", CellID, "", SourceData.Rows[r].ItemArray[c].ToString().Trim() == "TRUE" ? true : false, false); break; default: break; } } string DBFieldID = SourceData.Rows[r].ItemArray[DbTableUniqueIDColumnNumber].ToString(); f.DBFieldID = DBFieldID; return(f); }
public static void Main(string[] args) { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); // load input PDF file Document doc = new Document(dataDir + "input.pdf"); TextBoxField field = (TextBoxField)doc.Form["textbox1"]; //2 digits after point //no separator //neg style = minus //no currency field.Actions.OnModifyCharacter = new JavascriptAction("AFNumber_Keystroke(2, 1, 1, 0, \"\", true)"); field.Actions.OnFormat = new JavascriptAction("AFNumber_Format(2, 1, 1, 0, \"\", true)"); // set initial field value field.Value = "123"; // save resultant PDF doc.Save(dataDir + "Restricted_out.pdf"); }
// // Debug methods // for testing functionality Aspose.PDF // public static void Form1(Document pdfDocument) { Page pdfPage = pdfDocument.Pages.Add(); TextFragment textFragment1 = new TextFragment("tF: "); //Console.WriteLine("textFragment1.Rectangle.Height: " + textFragment1.Rectangle.Height); textFragment1.Margin = new MarginInfo(0, 10-16, 0, 12); // = textFragment1.Rectangle.Height - formField.Height //textFragment1.Margin = new MarginInfo(0, 10-16, 0, 0); // = textFragment1.Rectangle.Height - formField.Height TextBoxField formField = new TextBoxField(); formField.Height = 16; formField.Width = 100; formField.Margin = new MarginInfo(0, 12, 0, 12); formField.PartialName = "Text"; // ???? formField.Value = "ttt"; formField.IsInLineParagraph = true; TextFragment textFragment2 = new TextFragment("Tf 2."); textFragment2.IsInLineParagraph = true; pdfPage.Paragraphs.Add(textFragment1); pdfPage.Paragraphs.Add(formField); pdfPage.Paragraphs.Add(textFragment2); }
protected void EditForm_ItemInserting(object sender, DetailsViewInsertEventArgs e) { if (e == null) { return; } if (!UserChecked) { e.Cancel = true; string loginName = e.Values["Email"].ToString(); string firstName = string.Empty; string middleName = string.Empty; string lastName = string.Empty; if (LoginProvider.Current.LoginNameExists(loginName)) { if (LoginProvider.Current.LoginInOrganization(loginName, m_UserContext.OrganizationId)) { ErrorPanel.InnerHtml = Resources.UsersControl_ErrorMessage_UserInOrganizationExists; ErrorPanel.Visible = true; return; } ClientDataSet.UserRow userRow = UserProvider.GetUserRow(loginName); if (userRow != null) { firstName = userRow.FirstName; middleName = userRow.MiddleName; lastName = userRow.LastName; } } TextBoxField field = (EditForm.Fields[0] as TextBoxField); if (field != null) { field.DefaultText = loginName; field.ReadOnly = true; } field = (EditForm.Fields[1] as TextBoxField); if (field != null) { field.DefaultText = firstName; } field = (EditForm.Fields[2] as TextBoxField); if (field != null) { field.DefaultText = middleName; } field = (EditForm.Fields[3] as TextBoxField); if (field != null) { field.DefaultText = lastName; } UserChecked = true; EditForm_ShowDetails(true); } }
public static TextBoxField NewTextBoxField(TextBoxFieldType type, string name = null) { TextBoxField field; if (type == TextBoxFieldType.Small) { field = new TextBoxField { Id = Guid.NewGuid(), Name = "Lock Info", Tooltip = "The lock combination", IsMultiline = false, Value = "124-1515-15155", CreatedDate = DateTime.UtcNow, LastModified = DateTime.UtcNow }; } else { field = new TextBoxField { Id = Guid.NewGuid(), Name = "Notes", Tooltip = "Any miscellaneous service information", IsMultiline = true, Value = "Be careful, there is a large scary dog", CreatedDate = DateTime.UtcNow, LastModified = DateTime.UtcNow }; } if (name != null) field.Name = name; return field; }
public static void CreateFormField() { PdfDocument document = new PdfDocument(); PdfPage page = document.Pages.AddPage(); PageContentBuilder builder = new PageContentBuilder(page); double padding = 10; double topOffset = 100; //Create CheckBox FormField CheckBoxField check = new CheckBoxField("checkBox1"); check.IsChecked = true; //Add CheckBox to document fields document.AcroForm.FormFields.Add(check); //Draw CheckBox to page builder.Position.Translate(50, topOffset); builder.DrawWidget(check, new Size(10, 10)); //Draw CheckBox description builder.Position.Translate(50 + 10 + padding, topOffset); builder.DrawText("CheckBox"); //Create ComboBox FormField ComboBoxField combo = new ComboBoxField("comboBox1"); combo.TextState.FontSize = 16; combo.Options.Add(new ChoiceOption("Combo 1")); combo.Options.Add(new ChoiceOption("Combo 2")); combo.Options.Add(new ChoiceOption("Combo 3")); combo.Value = combo.Options[2]; //Add ComboBox to document fields document.AcroForm.FormFields.Add(combo); //Draw ComboBox to page topOffset += 30; builder.Position.Translate(50, topOffset); builder.DrawWidget(combo, new Size(100, 30)); //Draw ComboBox description builder.Position.Translate(50 + 100 + padding, topOffset); builder.DrawText("ComboBox"); //Create ListBox FormField ListBoxField list = new ListBoxField("listBox1"); list.AllowMultiSelection = true; list.TextState.FontSize = 16; list.Options.Add(new ChoiceOption("List 1")); list.Options.Add(new ChoiceOption("List 2")); list.Options.Add(new ChoiceOption("List 3")); list.Value = new ChoiceOption[] { list.Options[0], list.Options[2] }; //Add ListBox to document fields document.AcroForm.FormFields.Add(list); //Draw ListBox to page topOffset += 30; builder.Position.Translate(50, topOffset); builder.DrawWidget(list, new Size(100, 100)); //Draw ListBox description builder.Position.Translate(50 + 100 + padding, topOffset); builder.DrawText("ListBox"); //Create RadioButton FormField RadioButtonField radio = new RadioButtonField("radioButton1"); radio.Options.Add(new RadioOption("Radio 1")); radio.Options.Add(new RadioOption("Radio 2")); radio.Value = radio.Options[1]; //Add RadioButton to document fields document.AcroForm.FormFields.Add(radio); //Draw RadioButton to page topOffset += 100; foreach (RadioOption option in radio.Options) { topOffset += 30; builder.Position.Translate(50, topOffset); builder.DrawWidget(radio, option, new Size(10, 10)); } //Draw ListBox description builder.Position.Translate(50 + 10 + padding, topOffset); builder.DrawText("RadioButton"); //Create TextBox FormField TextBoxField textBox = new TextBoxField("textBox1"); textBox.TextState.FontSize = 16; textBox.Value = "Input..."; //Add TextBox to document fields document.AcroForm.FormFields.Add(textBox); //Draw TextBox to page topOffset += 30; builder.Position.Translate(50, topOffset); builder.DrawWidget(textBox, new Size(100, 30)); //Draw TextBox description builder.Position.Translate(50 + 100 + padding, topOffset); builder.DrawText("TextBox"); using (FileStream fs = File.OpenWrite("CreateFormField.pdf")) { PdfFile pdfFile = new PdfFile(); pdfFile.Export(document, fs); } }
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); } }
public static void Run() { // ExStart:1 // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Text(); string outputFile = dataDir + "TextBlock_HideShow_MouseOverOut_out.pdf"; // Create sample document with text Document doc = new Document(); doc.Pages.Add().Paragraphs.Add(new TextFragment("Move the mouse cursor here to display floating text")); doc.Save(outputFile); // Open document with text Document document = new Document(outputFile); // Create TextAbsorber object to find all the phrases matching the regular expression TextFragmentAbsorber absorber = new TextFragmentAbsorber("Move the mouse cursor here to display floating text"); // Accept the absorber for the document pages document.Pages.Accept(absorber); // Get the first extracted text fragment TextFragmentCollection textFragments = absorber.TextFragments; TextFragment fragment = textFragments[1]; // Create hidden text field for floating text in the specified rectangle of the page TextBoxField floatingField = new TextBoxField(fragment.Page, new Rectangle(100, 700, 220, 740)); // Set text to be displayed as field value floatingField.Value = "This is the \"floating text field\"."; // We recommend to make field 'readonly' for this scenario floatingField.ReadOnly = true; // Set 'hidden' flag to make field invisible on document opening floatingField.Flags |= AnnotationFlags.Hidden; // Setting a unique field name isn't necessary but allowed floatingField.PartialName = "FloatingField_1"; // Setting characteristics of field appearance isn't necessary but makes it better floatingField.DefaultAppearance = new DefaultAppearance("Helv", 10, System.Drawing.Color.Blue); floatingField.Characteristics.Background = System.Drawing.Color.LightBlue; floatingField.Characteristics.Border = System.Drawing.Color.DarkBlue; floatingField.Border = new Border(floatingField); floatingField.Border.Width = 1; floatingField.Multiline = true; // Add text field to the document document.Form.Add(floatingField); // Create invisible button on text fragment position ButtonField buttonField = new ButtonField(fragment.Page, fragment.Rectangle); // Create new hide action for specified field (annotation) and invisibility flag. // (You also may reffer floating field by the name if you specified it above.) // Add actions on mouse enter/exit at the invisible button field buttonField.Actions.OnEnter = new HideAction(floatingField, false); buttonField.Actions.OnExit = new HideAction(floatingField); // Add button field to the document document.Form.Add(buttonField); // Save document document.Save(outputFile); // ExEnd:1 }
private static void DrawPageWithWidgets(RadFixedDocument document) { RadFixedPage page = document.Pages.AddPage(); FixedContentEditor editor = new FixedContentEditor(page); using (editor.SaveGraphicProperties()) { editor.GraphicProperties.IsFilled = true; editor.GraphicProperties.IsStroked = false; editor.GraphicProperties.StrokeThickness = 0; editor.GraphicProperties.FillColor = new RgbColor(209, 178, 234); editor.DrawRectangle(new Rect(50, 50, editor.Root.Size.Width - 100, editor.Root.Size.Height - 100)); } editor.Position.Translate(100, 100); Size widgetDimensions = new Size(200, 30); foreach (FormField field in document.AcroForm.FormFields) { switch (field.FieldType) { case FormFieldType.CheckBox: CheckBoxField check = (CheckBoxField)field; DrawNextWidgetWithDescription(editor, "CheckBox", (e) => e.DrawWidget(check, widgetDimensions)); break; case FormFieldType.ComboBox: ComboBoxField combo = (ComboBoxField)field; DrawNextWidgetWithDescription(editor, "ComboBox", (e) => e.DrawWidget(combo, widgetDimensions)); break; case FormFieldType.CombTextBox: CombTextBoxField comb = (CombTextBoxField)field; DrawNextWidgetWithDescription(editor, "Comb TextBox", (e) => e.DrawWidget(comb, widgetDimensions)); break; case FormFieldType.ListBox: ListBoxField list = (ListBoxField)field; DrawNextWidgetWithDescription(editor, "ListBox", (e) => e.DrawWidget(list, new Size(widgetDimensions.Width, widgetDimensions.Width))); break; case FormFieldType.PushButton: PushButtonField push = (PushButtonField)field; DrawNextWidgetWithDescription(editor, "Button", (e) => e.DrawWidget(push, widgetDimensions)); break; case FormFieldType.RadioButton: RadioButtonField radio = (RadioButtonField)field; foreach (RadioOption option in radio.Options) { DrawNextWidgetWithDescription(editor, option.Value, (e) => e.DrawWidget(radio, option, widgetDimensions)); } break; case FormFieldType.Signature: SignatureField signature = (SignatureField)field; DrawNextWidgetWithDescription(editor, "Signature", (e) => e.DrawWidget(signature, widgetDimensions)); break; case FormFieldType.TextBox: TextBoxField textBox = (TextBoxField)field; DrawNextWidgetWithDescription(editor, "TextBox", (e) => e.DrawWidget(textBox, widgetDimensions)); break; } } }
public static void UploadPic(List <shap> shapes, string filename, string aspectRatio) { Document doc = new Document(HttpContext.Current.Server.MapPath("Convert/output.pdf")); //Create image stamp ImageStamp imageStamp = new ImageStamp(HttpContext.Current.Server.MapPath("test.png")); for (int i = 0; i < shapes.Count; i++) { //create stamp Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); float shapeX = (shapes[i].x * 72 / 150) / (float)Convert.ToDouble(shapes[i].ratio); float shapeY = (shapes[i].y * 72 / 150) / (float)Convert.ToDouble(shapes[i].ratio); float shapeW = (shapes[i].w * 72 / 150) / (float)Convert.ToDouble(shapes[i].ratio); float shapeH = (shapes[i].h * 72 / 150) / (float)Convert.ToDouble(shapes[i].ratio); double yaxis = (float)(doc.Pages[shapes[i].p].Rect.URY - (shapeH + shapeY)); var isSpecial = true;//regexItem.IsMatch(shapes[i].imName); if (shapes[i].Itype == "highlight" || shapes[i].Itype == "image") { if (shapes[i].Itype == "highlight") { imageStamp = new ImageStamp(HttpContext.Current.Server.MapPath("test.png")); } else { imageStamp = new ImageStamp(HttpContext.Current.Server.MapPath("Images/" + shapes[i].imName)); } imageStamp.Background = false; imageStamp.XIndent = (float)(shapeX); imageStamp.YIndent = (float)(yaxis); imageStamp.Height = shapeH; imageStamp.Width = shapeW; //Add stamp to particular page doc.Pages[shapes[i].p].AddStamp(imageStamp); } else if (shapes[i].Itype == "text") { /* * // create TextBuilder for first page * TextBuilder tb = new TextBuilder(doc.Pages[shapes[i].p]); * * // TextFragment with sample text * TextFragment fragment = new TextFragment(shapes[i].t); * * // set the font for TextFragment * fragment.TextState.Font = FontRepository.FindFont(shapes[i].n); * fragment.TextState.FontSize = Convert.ToInt32(shapes[i].s); * if (shapes[i].wt == "bold") * { * fragment.TextState.FontStyle = FontStyles.Bold; * } * * if (shapes[i].st == "italic") * { * fragment.TextState.FontStyle = FontStyles.Italic; * } * * // set the formatting of text as Underline * // fragment.TextState.Underline = true; * fragment.TextState.ForegroundColor = GetColor(shapes[i].c); * // specify the position where TextFragment needs to be placed * fragment.Position = new Position((float)(shapeX), (float)(yaxis)); * * // fragment.Rectangle.Rotate((360 - (Convert.ToDouble(shapes[i].fieldType)) * 180 / Math.PI); * * // append TextFragment to PDF file * tb.AppendText(fragment); */ //create text stamp TextStamp textStamp = new TextStamp(shapes[i].t); //set whether stamp is background // textStamp.Background = true; //set origin textStamp.XIndent = (float)(shapeX); textStamp.YIndent = (float)(yaxis); //rotate stamp textStamp.RotateAngle = 360 - ((Convert.ToDouble(shapes[i].fieldType)) * 180 / Math.PI); //set text properties textStamp.TextState.Font = FontRepository.FindFont(shapes[i].n); textStamp.TextState.FontSize = Convert.ToInt32(shapes[i].s) * 0.75f; if (shapes[i].wt == "bold") { textStamp.TextState.FontStyle = FontStyles.Bold; } if (shapes[i].st == "italic") { textStamp.TextState.FontStyle = FontStyles.Italic; } textStamp.TextState.ForegroundColor = GetColor(shapes[i].c); //add stamp to particular page doc.Pages[shapes[i].p].AddStamp(textStamp); } else if (shapes[i].Itype == "field" && isSpecial) { if (shapes[i].fieldType == "Text") { // Get a field TextBoxField textBoxField = doc.Form.Fields[Convert.ToInt32(shapes[i].imName)] as TextBoxField; // Modify field value textBoxField.Value = shapes[i].t; } else if (shapes[i].fieldType == "CheckBox") { // Get a field CheckboxField checkBoxField = doc.Form.Fields[Convert.ToInt32(shapes[i].imName)] as CheckboxField; if (shapes[i].t != "") { // Modify field value checkBoxField.Checked = Convert.ToBoolean(shapes[i].t); } } else if (shapes[i].fieldType == "Radio") { RadioButtonOptionField field = (RadioButtonOptionField)doc.Form.Fields[Convert.ToInt32(shapes[i].imName)]; RadioButtonField rbf = (RadioButtonField)field.Parent; if (Convert.ToBoolean(shapes[i].t)) { rbf.Selected = rbf.Options[field.OptionName].Index; } else { field.ActiveState = "Off"; } } else if (shapes[i].fieldType == "ComboBox") { // Get a field ComboBoxField comboBoxField = doc.Form.Fields[Convert.ToInt32(shapes[i].imName)] as ComboBoxField; var values = shapes[i].t.Split(new string[] { "^^^" }, StringSplitOptions.None)[0]; foreach (var item in comboBoxField.Options.Cast <Option>()) { if (item.Value == values) { comboBoxField.Selected = item.Index; } } } } } doc.Save(HttpContext.Current.Server.MapPath("Convert/Export.pdf")); }
public IHttpActionResult UploadPic(UploadPicModel uploadPicModel) { var fullPath = Path.Combine(Config.Configuration.WorkingDirectory, "Editor", uploadPicModel.documentId); var downloadFileName = "document.pdf"; var documentFileName = Path.Combine(Config.Configuration.WorkingDirectory, "Editor", uploadPicModel.documentId, downloadFileName); Document doc = new Document(documentFileName); //Create image stamp ImageStamp imageStamp = new ImageStamp(HttpContext.Current.Server.MapPath("/img/Test.png")); for (int i = 0; i < uploadPicModel.shapes.Count; i++) { //create stamp Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); float shapeX = (uploadPicModel.shapes[i].x * 72 / 150) / (float)Convert.ToDouble(uploadPicModel.shapes[i].ratio); float shapeY = (uploadPicModel.shapes[i].y * 72 / 150) / (float)Convert.ToDouble(uploadPicModel.shapes[i].ratio); float shapeW = (uploadPicModel.shapes[i].w * 72 / 150) / (float)Convert.ToDouble(uploadPicModel.shapes[i].ratio); float shapeH = (uploadPicModel.shapes[i].h * 72 / 150) / (float)Convert.ToDouble(uploadPicModel.shapes[i].ratio); double yaxis = (float)(doc.Pages[uploadPicModel.shapes[i].p].Rect.URY - (shapeH + shapeY)); var isSpecial = true; //regexItem.IsMatch(uploadPicModel.shapes[i].imName); if (uploadPicModel.shapes[i].Itype == "highlight" || uploadPicModel.shapes[i].Itype == "image") { imageStamp = uploadPicModel.shapes[i].Itype == "highlight" ? new ImageStamp(HttpContext.Current.Server.MapPath("/img/test.png")) : new ImageStamp(fullPath + uploadPicModel.shapes[i].imName); imageStamp.Background = false; imageStamp.XIndent = (float)(shapeX); imageStamp.YIndent = (float)(yaxis); imageStamp.Height = shapeH; imageStamp.Width = shapeW; //Add stamp to particular page doc.Pages[uploadPicModel.shapes[i].p].AddStamp(imageStamp); } else if (uploadPicModel.shapes[i].Itype == "text") { //create text stamp TextStamp textStamp = new TextStamp(uploadPicModel.shapes[i].t); textStamp.XIndent = (float)(shapeX); textStamp.YIndent = (float)(yaxis); //rotate stamp textStamp.RotateAngle = 360 - (Convert.ToDouble(uploadPicModel.shapes[i].fieldType) * 180 / Math.PI); //set text properties textStamp.TextState.Font = FontRepository.FindFont(uploadPicModel.shapes[i].n); textStamp.TextState.FontSize = Convert.ToInt32(uploadPicModel.shapes[i].s) * 0.75f; if (uploadPicModel.shapes[i].wt == "bold") { textStamp.TextState.FontStyle = FontStyles.Bold; } if (uploadPicModel.shapes[i].st == "italic") { textStamp.TextState.FontStyle = FontStyles.Italic; } textStamp.TextState.ForegroundColor = GetColor(uploadPicModel.shapes[i].c); //add stamp to particular page doc.Pages[uploadPicModel.shapes[i].p].AddStamp(textStamp); } else if (uploadPicModel.shapes[i].Itype == "field" && isSpecial) { if (uploadPicModel.shapes[i].fieldType == "Text") { // Get a field TextBoxField textBoxField = doc.Form.Fields[Convert.ToInt32(uploadPicModel.shapes[i].imName)] as TextBoxField; // Modify field value textBoxField.Value = uploadPicModel.shapes[i].t; } else if (uploadPicModel.shapes[i].fieldType == "CheckBox") { // Get a field CheckboxField checkBoxField = doc.Form.Fields[Convert.ToInt32(uploadPicModel.shapes[i].imName)] as CheckboxField; if (uploadPicModel.shapes[i].t != "") { // Modify field value checkBoxField.Checked = Convert.ToBoolean(uploadPicModel.shapes[i].t); } } else if (uploadPicModel.shapes[i].fieldType == "Radio") { RadioButtonOptionField field = (RadioButtonOptionField)doc.Form.Fields[Convert.ToInt32(uploadPicModel.shapes[i].imName)]; RadioButtonField rbf = (RadioButtonField)field.Parent; if (Convert.ToBoolean(uploadPicModel.shapes[i].t)) { rbf.Selected = rbf.Options[field.OptionName].Index; } else { field.ActiveState = "Off"; } } else if (uploadPicModel.shapes[i].fieldType == "ComboBox") { // Get a field ComboBoxField comboBoxField = doc.Form.Fields[Convert.ToInt32(uploadPicModel.shapes[i].imName)] as ComboBoxField; var values = uploadPicModel.shapes[i].t.Split(new[] { "^^^" }, StringSplitOptions.None)[0]; foreach (var item in comboBoxField.Options.Cast <Option>()) { if (item.Value == values) { comboBoxField.Selected = item.Index; } } } } } doc.Save(Config.Configuration.OutputDirectory + "/Export.pdf"); return(Ok(new DocStatusModel())); }
private static TextBoxField CreateTextBoxField(Page page, string name) { var textBoxField = new TextBoxField(page, new Rectangle(100, 200, 300, 400)) { Name = name, PartialName = name, MappingName = name, AlternateName = name + 1 }; var border = new Aspose.Pdf.InteractiveFeatures.Annotations.Border(textBoxField) { Width = 5, Dash = new Aspose.Pdf.InteractiveFeatures.Annotations.Dash(1, 1) }; textBoxField.Border = border; textBoxField.Value = ""; return textBoxField; }