Skip to content

Commit c1905f2

Browse files
Merge pull request #487 from telerik/new-kb-radpdfprocessing-customize-textboxfield-colors-8b6d282f9000452594abd22c900a4667
Added new kb article radpdfprocessing-customize-textboxfield-colors
2 parents c7b3214 + a1c1101 commit c1905f2

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed
15.7 KB
Loading
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
![Highlight TextBox Field](images/highlight-textbox-field.gif)
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+

libraries/radpdfprocessing/model/interactive-forms/form-fields/textboxfield.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,4 @@ TextBoxField exposes the following properties:
9090
* [CombTextBoxField Class]({%slug radpdfprocessing-model-interactive-forms-form-fields-combtextboxfield%})
9191
* [Create Interactive Forms SDK example](https://github.com/telerik/document-processing-sdk/tree/master/PdfProcessing/CreateInteractiveForms)
9292
* [Modifying Forms SDK example](https://github.com/telerik/document-processing-sdk/tree/master/PdfProcessing/ModifyForms)
93+
* [Customizing Text and Border Colors to Highlight a TextBoxField with RadPdfProcessing]({%slug radpdfprocessing-customize-textboxfield-colors%})

0 commit comments

Comments
 (0)