@@ -14,44 +14,53 @@ static void Main(string[] args)
1414 {
1515 using ( WordDocument document = new WordDocument ( fileStream , FormatType . Docx ) )
1616 {
17- // Find and update size for all checkbox form fields.
17+ // Update checkbox form fields
1818 List < Entity > checkBoxes = document . FindAllItemsByProperty ( EntityType . CheckBox , null , null ) ;
1919 foreach ( Entity entity in checkBoxes )
2020 {
2121 WCheckBox checkBox = ( WCheckBox ) entity ;
2222 checkBox . SizeType = CheckBoxSizeType . Exactly ;
23- checkBox . CheckBoxSize = 20 ;
23+ checkBox . CheckBoxSize = 20 ;
2424 }
2525
26- // Find and update size for all text form fields.
26+ // Update dropdown form fields
27+ List < Entity > dropDowns = document . FindAllItemsByProperty ( EntityType . DropDownFormField , null , null ) ;
28+ foreach ( Entity entity in dropDowns )
29+ {
30+ SetFontSizeForFormField ( ( WDropDownFormField ) entity ) ;
31+ }
32+
33+ // Update text form fields
2734 List < Entity > textFormFields = document . FindAllItemsByProperty ( EntityType . TextFormField , null , null ) ;
2835 foreach ( Entity entity in textFormFields )
2936 {
30- WTextFormField textFormField = ( WTextFormField ) entity ;
31- Entity currentEntity = textFormField ;
32-
33- // Iterate through sibling items until reaching the Field End marker.
34- while ( currentEntity . NextSibling != null )
35- {
36- if ( currentEntity is WTextRange )
37- {
38- // Set font size for text ranges within the form field.
39- ( currentEntity as WTextRange ) . CharacterFormat . FontSize = 14 ;
40- }
41- else if ( currentEntity is WFieldMark fieldMark && fieldMark . Type == FieldMarkType . FieldEnd )
42- {
43- break ;
44- }
45- // Move to the next sibling entity.
46- currentEntity = ( Entity ) currentEntity . NextSibling ;
47- }
37+ SetFontSizeForFormField ( ( WTextFormField ) entity ) ;
4838 }
4939 // Save the modified document
5040 using ( FileStream outputStream = new FileStream ( Path . GetFullPath ( @"Output/Result.docx" ) , FileMode . Create , FileAccess . ReadWrite ) )
5141 {
5242 document . Save ( outputStream , FormatType . Docx ) ;
5343 }
5444 }
45+ }
46+ /// <summary>
47+ /// Sets the font size for text ranges within a form field until the Field End marker is reached.
48+ /// </summary>
49+ static void SetFontSizeForFormField ( Entity formField )
50+ {
51+ Entity currentEntity = formField ;
52+ while ( currentEntity . NextSibling != null )
53+ {
54+ if ( currentEntity is WTextRange textRange )
55+ {
56+ textRange . CharacterFormat . FontSize = 20 ;
57+ }
58+ else if ( currentEntity is WFieldMark fieldMark && fieldMark . Type == FieldMarkType . FieldEnd )
59+ {
60+ break ;
61+ }
62+ currentEntity = ( Entity ) currentEntity . NextSibling ;
63+ }
5564 }
5665 }
5766 }
0 commit comments