|
| 1 | +--- |
| 2 | +title: Customizing Text and Border Colors to Highlight a TextBoxField with RadPdfProcessing |
| 3 | +description: Learn how to alter the text and border colors to highlight a TextBoxField within a PDF document using RadPdfProcessing. |
| 4 | +type: how-to |
| 5 | +page_title: How to Change Text and Border Colors to Highlight a TextBoxField with RadPdfProcessing |
| 6 | +slug: radpdfprocessing-customize-textboxfield-colors |
| 7 | +tags: pdfprocessing, document, processing, textbox, field, color, border, customization, pdf, highlight |
| 8 | +res_type: kb |
| 9 | +ticketid: 1673638 |
| 10 | +--- |
| 11 | + |
| 12 | +## Environment |
| 13 | + |
| 14 | +| Version | Product | Author | |
| 15 | +| --- | --- | ---- | |
| 16 | +| 2024.4.1106| RadPdfProcessing |[Desislava Yordanova](https://www.telerik.com/blogs/author/desislava-yordanova)| |
| 17 | + |
| 18 | +## Description |
| 19 | + |
| 20 | +When creating PDF documents containing [form fields]({%slug radpdfprocessing-model-interactive-forms-form-fields%}), you might need to update the text and border colors of a [TextBoxField]({%slug radpdfprocessing-model-interactive-forms-form-fields-textboxfield%}) and highlight specific fields. This article demonstrates how to customize the appearance of `TextBoxField` elements, including changing their text and border colors. |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | +## Solution |
| 25 | + |
| 26 | +To change the text and border colors of a `TextBoxField` in a PDF document, utilize the `TextProperties` and `AppearanceCharacteristics` properties provided by the [VariableContentWidget]({%slug radpdfprocessing-model-annotations-widgets%}) class. The following example demonstrates how to customize these aspects. |
| 27 | + |
| 28 | +1. Create a new [RadFixedDocument]({%slug radpdfprocessing-model-radfixeddocument%}) and add a page to it. |
| 29 | +2. Instantiate a `TextBoxField` and configure its properties as needed. |
| 30 | +3. Add a widget to the `TextBoxField` and set up the text and border colors using the `TextProperties` and [AppearanceCharacteristics]({%slug radpdfprocessing-model-interactive-forms-dynamic-appearance-properties%}) properties. |
| 31 | +4. Recalculate the content of the widget and add the `TextBoxField` to the document. |
| 32 | +5. Save the document to a file. |
| 33 | + |
| 34 | +```csharp |
| 35 | +RadFixedDocument fixedDocument = new RadFixedDocument(); |
| 36 | +fixedDocument.Pages.AddPage(); |
| 37 | + |
| 38 | +TextBoxField textField = new TextBoxField("SampleTextBox") |
| 39 | +{ |
| 40 | + MaxLengthOfInputCharacters = 500, |
| 41 | + IsMultiline = true, |
| 42 | + IsPassword = false, |
| 43 | + IsFileSelect = false, |
| 44 | + ShouldSpellCheck = true, |
| 45 | + AllowScroll = true, |
| 46 | + Value = "Sample content", |
| 47 | +}; |
| 48 | + |
| 49 | +VariableContentWidget widget = textField.Widgets.AddWidget(); |
| 50 | +VariableTextProperties textProperties = new VariableTextProperties(); |
| 51 | +textProperties.Fill = new RgbColor(255, 0, 0); // Set text color to red |
| 52 | +textProperties.FontSize = 24; |
| 53 | +widget.TextProperties = textProperties; |
| 54 | + |
| 55 | +widget.AppearanceCharacteristics.BorderColor = new RgbColor(0, 0, 0); // Set border color to black |
| 56 | +widget.AppearanceCharacteristics.Background = new RgbColor(255, 255, 0); // Optional: Set background color to yellow |
| 57 | +widget.Rect = new Rect(10, 10, 250, 50); |
| 58 | +widget.RecalculateContent(); |
| 59 | + |
| 60 | +fixedDocument.AcroForm.FormFields.Add(textField); |
| 61 | +fixedDocument.Pages[0].Annotations.Add(widget); |
| 62 | + |
| 63 | +string fileName = "CustomizedTextBoxField.pdf"; |
| 64 | +File.WriteAllBytes(fileName, new PdfFormatProvider().Export(fixedDocument, TimeSpan.FromSeconds(10))); |
| 65 | + |
| 66 | +Console.WriteLine("Document with customized TextBoxField created."); |
| 67 | +``` |
| 68 | + |
| 69 | +The demonstrated approach is applicable not only for creating new documents, but for importing documents that already contains form fields as well. |
| 70 | + |
| 71 | +## See Also |
| 72 | + |
| 73 | +- [TextBoxField Documentation]({%slug radpdfprocessing-model-interactive-forms-form-fields-textboxfield%}) |
| 74 | +- [Text and Graphic Properties]({%slug radpdfprocessing-editing-text-and-graphic-properties%}) |
| 75 | +- [Create Interactive Forms SDK Example](https://github.com/telerik/document-processing-sdk/tree/master/PdfProcessing/CreateInteractiveForms) |
| 76 | +- [Modify Form Values SDK Example](https://github.com/telerik/document-processing-sdk/tree/master/PdfProcessing/ModifyForms) |
| 77 | + |
0 commit comments