|
| 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 | + |
0 commit comments