Skip to content

Commit 07c15fd

Browse files
Merge pull request #186 from SyncfusionExamples/963561
963561: Added sample code for checkmark and radio button colors in PDF document
2 parents 0bc58de + 020a0c6 commit 07c15fd

File tree

5 files changed

+81
-0
lines changed

5 files changed

+81
-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 17
4+
VisualStudioVersion = 17.14.36221.1 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Customize-indicator-colors", "Customize-indicator-colors\Customize-indicator-colors.csproj", "{D5A2EFE1-DF64-41CA-9A25-A1A2EECA37EA}"
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+
{D5A2EFE1-DF64-41CA-9A25-A1A2EECA37EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{D5A2EFE1-DF64-41CA-9A25-A1A2EECA37EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{D5A2EFE1-DF64-41CA-9A25-A1A2EECA37EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{D5A2EFE1-DF64-41CA-9A25-A1A2EECA37EA}.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 = {89B8EE92-DFEA-4816-A09F-0612E45354F5}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Customize_indicator_colors</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
</Project>
Binary file not shown.

Forms/Customize-indicator-colors/.NET/Customize-indicator-colors/Output/gitkeep.txt

Whitespace-only changes.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using Syncfusion.Drawing;
2+
using Syncfusion.Pdf.Parsing;
3+
4+
// Open the input PDF file stream.
5+
using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read))
6+
{
7+
// Load the PDF document from the input stream.
8+
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream);
9+
10+
// Access the existing form fields in the PDF.
11+
PdfLoadedForm form = loadedDocument.Form;
12+
13+
// Iterate through all form fields to find checkboxes and radio button lists.
14+
foreach (PdfLoadedField field in form.Fields)
15+
{
16+
// If the field is a checkbox, change its checkmark color using ForeColor.
17+
if (field is PdfLoadedCheckBoxField checkBoxField)
18+
{
19+
checkBoxField.ForeColor = Color.Red; // Set desired checkbox color.
20+
}
21+
// If the field is a radio button list, change each item's dot color.
22+
else if (field is PdfLoadedRadioButtonListField radioButtonField)
23+
{
24+
foreach (PdfLoadedRadioButtonItem item in radioButtonField.Items)
25+
{
26+
item.ForeColor = Color.Blue; // Set desired radio button color.
27+
}
28+
}
29+
}
30+
// Disable the default appearance to allow custom rendering of form fields.
31+
form.SetDefaultAppearance(false);
32+
// Create the output file stream.
33+
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
34+
{
35+
// Save the modified PDF document to the new file stream.
36+
loadedDocument.Save(outputFileStream);
37+
}
38+
39+
// Close the PDF document.
40+
loadedDocument.Close(true);
41+
}

0 commit comments

Comments
 (0)