|
| 1 | +--- |
| 2 | +title: Customizing Text and Border Color in TextBoxField in RadPdfProcessing |
| 3 | +description: Learn how to alter the text and border colors for a TextBoxField within a PDF document using RadPdfProcessing. |
| 4 | +type: how-to |
| 5 | +page_title: How to Change Text and Border Colors for TextBoxFields with RadPdfProcessing |
| 6 | +slug: radpdfprocessing-customize-textboxfield-colors |
| 7 | +tags: radpdfprocessing, document processing, textboxfield, color customization, pdf |
| 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 working with PDF documents, you might need to update the text and border colors of a `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 | +## Solution |
| 23 | + |
| 24 | +To change the text and border colors of a `TextBoxField` in a PDF document, utilize the `TextProperties` and `AppearanceCharacteristics` properties provided by the `VariableContentWidget` class. The following example demonstrates how to customize these aspects. |
| 25 | + |
| 26 | +1. Create a new `RadFixedDocument` and add a page to it. |
| 27 | +2. Instantiate a `TextBoxField` and configure its properties as needed. |
| 28 | +3. Add a widget to the `TextBoxField` and set up the text and border colors using the `TextProperties` and `AppearanceCharacteristics` properties. |
| 29 | +4. Recalculate the content of the widget and add the `TextBoxField` to the document. |
| 30 | +5. Save the document to a file. |
| 31 | + |
| 32 | +```csharp |
| 33 | +RadFixedDocument fixedDocument = new RadFixedDocument(); |
| 34 | +fixedDocument.Pages.AddPage(); |
| 35 | + |
| 36 | +TextBoxField textField = new TextBoxField("SampleTextBox") |
| 37 | +{ |
| 38 | + MaxLengthOfInputCharacters = 500, |
| 39 | + IsMultiline = true, |
| 40 | + IsPassword = false, |
| 41 | + IsFileSelect = false, |
| 42 | + ShouldSpellCheck = true, |
| 43 | + AllowScroll = true, |
| 44 | + Value = "Sample content", |
| 45 | +}; |
| 46 | + |
| 47 | +VariableContentWidget widget = textField.Widgets.AddWidget(); |
| 48 | +VariableTextProperties textProperties = new VariableTextProperties(); |
| 49 | +textProperties.Fill = new RgbColor(255, 0, 0); // Set text color to red |
| 50 | +textProperties.FontSize = 24; |
| 51 | +widget.TextProperties = textProperties; |
| 52 | + |
| 53 | +widget.AppearanceCharacteristics.BorderColor = new RgbColor(0, 0, 0); // Set border color to black |
| 54 | +widget.AppearanceCharacteristics.Background = new RgbColor(255, 255, 0); // Optional: Set background color to yellow |
| 55 | +widget.Rect = new Rect(10, 10, 250, 50); |
| 56 | +widget.RecalculateContent(); |
| 57 | + |
| 58 | +fixedDocument.AcroForm.FormFields.Add(textField); |
| 59 | +fixedDocument.Pages[0].Annotations.Add(widget); |
| 60 | + |
| 61 | +string fileName = "CustomizedTextBoxField.pdf"; |
| 62 | +File.WriteAllBytes(fileName, new PdfFormatProvider().Export(fixedDocument, TimeSpan.FromSeconds(10))); |
| 63 | + |
| 64 | +Console.WriteLine("Document with customized TextBoxField created."); |
| 65 | +``` |
| 66 | + |
| 67 | +## See Also |
| 68 | + |
| 69 | +- [TextBoxField Documentation](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/model/interactive-forms/form-fields/textboxfield) |
| 70 | +- [TextProperties Documentation](https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/model/interactive-forms/dynamic-appearance-properties) |
| 71 | +- [Create Interactive Forms SDK Example](https://github.com/telerik/document-processing-sdk/tree/master/PdfProcessing/CreateInteractiveForms) |
| 72 | +- [Modify Form Values SDK Example](https://github.com/telerik/document-processing-sdk/tree/master/PdfProcessing/ModifyForms) |
| 73 | + |
0 commit comments