Skip to content

Commit 2d8c8d5

Browse files
committed
add vb
1 parent 9654562 commit 2d8c8d5

File tree

5 files changed

+139
-0
lines changed

5 files changed

+139
-0
lines changed

VB/pdf-form-fields.sln

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Microsoft Visual Studio Solution File, Format Version 12.00
2+
# Visual Studio Version 16
3+
VisualStudioVersion = 16.0.30914.41
4+
MinimumVisualStudioVersion = 10.0.40219.1
5+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "pdf-form-fields", "pdf-form-fields\pdf-form-fields.vbproj", "{130D6D44-87AD-4CE1-98F4-1D8E04CC1250}"
6+
EndProject
7+
Global
8+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9+
Debug|Any CPU = Debug|Any CPU
10+
Release|Any CPU = Release|Any CPU
11+
EndGlobalSection
12+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
13+
{130D6D44-87AD-4CE1-98F4-1D8E04CC1250}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
14+
{130D6D44-87AD-4CE1-98F4-1D8E04CC1250}.Debug|Any CPU.Build.0 = Debug|Any CPU
15+
{130D6D44-87AD-4CE1-98F4-1D8E04CC1250}.Release|Any CPU.ActiveCfg = Release|Any CPU
16+
{130D6D44-87AD-4CE1-98F4-1D8E04CC1250}.Release|Any CPU.Build.0 = Release|Any CPU
17+
EndGlobalSection
18+
GlobalSection(SolutionProperties) = preSolution
19+
HideSolutionNode = FALSE
20+
EndGlobalSection
21+
GlobalSection(ExtensibilityGlobals) = postSolution
22+
SolutionGuid = {FEDB7A9E-F3A1-4595-9F9F-3706E7BDE023}
23+
EndGlobalSection
24+
EndGlobal
713 KB
Binary file not shown.
2.25 KB
Loading

VB/pdf-form-fields/Program.vb

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
Imports DevExpress.Pdf
2+
Imports System.Diagnostics
3+
4+
Namespace pdf_form_fields
5+
Friend Class Program
6+
Shared Sub Main(ByVal args() As String)
7+
Using pdfDocumentProcessor As New PdfDocumentProcessor()
8+
pdfDocumentProcessor.LoadDocument("Documents//FormDemo.pdf")
9+
10+
Dim documentFacade As PdfDocumentFacade = pdfDocumentProcessor.DocumentFacade
11+
Dim acroForm As PdfAcroFormFacade = documentFacade.AcroForm
12+
13+
'Change all form fields' color settings:
14+
Dim fields = acroForm.GetFields()
15+
For Each field As PdfFormFieldFacade In fields
16+
ChangeFormFieldColor(field)
17+
field.RebuildAppearance()
18+
Next field
19+
20+
'Obtain button form field parameters:
21+
Dim pushButton As PdfButtonFormFieldFacade = acroForm.GetButtonFormField("Submit")
22+
Dim buttonWidget As PdfButtonWidgetFacade = pushButton.Widgets(0)
23+
24+
'Specify a button icon and set its options:
25+
buttonWidget.SetNormalIcon("Documents//submit_3802014.png")
26+
buttonWidget.IconOptions.FitToAnnotationBounds = True
27+
buttonWidget.IconOptions.ScaleCondition = PdfIconScalingCircumstances.BiggerThanAnnotationRectangle
28+
buttonWidget.TextPosition = PdfWidgetAnnotationTextPosition.NoCaption
29+
30+
'Obtain the text form field properties
31+
32+
Dim visaField As PdfTextFormFieldFacade = acroForm.GetTextFormField("VisaNo")
33+
34+
'Divide field text into equally spaced positions:
35+
visaField.InputType = PdfTextFieldInputType.Comb
36+
visaField.Multiline = False
37+
38+
'Limit the number of inserted characters:
39+
visaField.MaxLength = 8
40+
41+
'Enable multiline text in the text field:
42+
Dim addressField As PdfTextFormFieldFacade = acroForm.GetTextFormField("Address")
43+
addressField.Multiline = True
44+
45+
addressField.Scrollable = True
46+
addressField.SpellCheck = False
47+
48+
'Set the radio group value:
49+
Dim genderField As PdfRadioGroupFormFieldFacade = acroForm.GetRadioGroupFormField("Gender")
50+
genderField.Value = genderField.Field.Items(2).Value
51+
52+
'Change marker style for all radio buttons:
53+
For Each widget As PdfRadioButtonWidgetFacade In genderField.Widgets
54+
widget.ButtonStyle = PdfAcroFormButtonStyle.Square
55+
Next widget
56+
57+
'Set combo box field value:
58+
Dim nationalityField As PdfComboBoxFormFieldFacade = acroForm.GetComboBoxFormField("Nationality")
59+
nationalityField.Value = nationalityField.Items(68).Value
60+
61+
'Disable user input:
62+
nationalityField.Editable = False
63+
64+
'Disable multiple selection:
65+
nationalityField.MultiSelect = False
66+
67+
'Sort list items alphabetically:
68+
nationalityField.Sorted = True
69+
70+
71+
pdfDocumentProcessor.SaveDocument("FormDemo_new.pdf")
72+
Process.Start(New ProcessStartInfo("FormDemo_new.pdf") With {.UseShellExecute = True})
73+
End Using
74+
End Sub
75+
76+
Private Shared Sub ChangeFormFieldColor(ByVal field As PdfFormFieldFacade)
77+
For Each pdfWidget As PdfWidgetFacade In field
78+
'Change color and border settings
79+
'For all form fields:
80+
pdfWidget.BorderWidth = 1
81+
pdfWidget.BackgroundColor = New PdfRGBColor(0.81, 0.81, 0.81)
82+
pdfWidget.BorderColor = New PdfRGBColor(0.47, 0.44, 0.67)
83+
pdfWidget.FontColor = New PdfRGBColor(0.34, 0.25, 0.36)
84+
85+
'Change border style for text form fields:
86+
If field.Type = PdfFormFieldType.Text Then
87+
pdfWidget.BorderStyle = PdfBorderStyle.Underline
88+
End If
89+
Next pdfWidget
90+
End Sub
91+
End Class
92+
End Namespace
93+
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>netcoreapp3.1</TargetFramework>
6+
<RootNamespace></RootNamespace>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="DevExpress.Document.Processor" Version="21.1.2-pre-21064" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<None Update="Documents\FormDemo.pdf">
15+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
16+
</None>
17+
<None Update="Documents\submit_3802014.png">
18+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
19+
</None>
20+
</ItemGroup>
21+
22+
</Project>

0 commit comments

Comments
 (0)