Skip to content

Commit a2186e5

Browse files
Merge pull request #350 from SyncfusionExamples/ES-942105-Specify-form-field-size
ES-942105- Add sample Specify-form-field-size
2 parents f53e1bc + 853f18c commit a2186e5

File tree

5 files changed

+106
-0
lines changed

5 files changed

+106
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.31911.196
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Specify-form-field-size", "Specify-form-field-size\Specify-form-field-size.csproj", "{D3AF529E-DB54-4294-A876-DD42E1E472D0}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{D3AF529E-DB54-4294-A876-DD42E1E472D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{D3AF529E-DB54-4294-A876-DD42E1E472D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{D3AF529E-DB54-4294-A876-DD42E1E472D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{D3AF529E-DB54-4294-A876-DD42E1E472D0}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {58137FF9-5AE1-4514-9929-3A8A7DA1DFEB}
24+
EndGlobalSection
25+
EndGlobal
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using Syncfusion.DocIO;
2+
using Syncfusion.DocIO.DLS;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
6+
namespace SpecifyFormFieldSize
7+
{
8+
class Program
9+
{
10+
static void Main(string[] args)
11+
{
12+
// Open the template Word document.
13+
using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.ReadWrite))
14+
{
15+
using (WordDocument document = new WordDocument(fileStream, FormatType.Docx))
16+
{
17+
// Find and update size for all checkbox form fields.
18+
List<Entity> checkBoxes = document.FindAllItemsByProperty(EntityType.CheckBox, null, null);
19+
foreach (Entity entity in checkBoxes)
20+
{
21+
WCheckBox checkBox = (WCheckBox)entity;
22+
checkBox.SizeType = CheckBoxSizeType.Exactly;
23+
checkBox.CheckBoxSize = 20;
24+
}
25+
26+
// Find and update size for all text form fields.
27+
List<Entity> textFormFields = document.FindAllItemsByProperty(EntityType.TextFormField, null, null);
28+
foreach (Entity entity in textFormFields)
29+
{
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+
}
48+
}
49+
// Save the modified document
50+
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite))
51+
{
52+
document.Save(outputStream, FormatType.Docx);
53+
}
54+
}
55+
}
56+
}
57+
}
58+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Specify_form_field_size</RootNamespace>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<None Update="Data\Template.docx">
15+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
16+
</None>
17+
<None Update="Output\.gitkeep">
18+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
19+
</None>
20+
</ItemGroup>
21+
22+
</Project>

0 commit comments

Comments
 (0)