Create formfields in PDF documents

PDF forms, Manipulate PDF
7/15/2015

This codesample shows how you can create different types of formfields in PDF

This sample may seem long, but it uses a lot of different field types in a lot of ways. The key-message here is to create an instance of a formfield, assigning a widget to it and setting layout values of the widget.

create-form-fields-pdf.png

C# code sample

1 //New document 2 Document document = new Document(); 3 4 Page page = new Page(PageSize.A4); 5 document.Pages.Add(page); 6 7 //TextBox Field with all default values 8 { 9 TextShape textShape = new TextShape( 250, page.Height - 50, "TextBox Field with all default values", Font.Helvetica, 12 ); 10 page.VisualOverlay.Add( textShape ); 11 12 TextField field = new TextField("FieldName1"); 13 Widget widget = new Widget(10, page.Height - 50, 200, 15); 14 15 field.Widgets.Add(widget); 16 page.Widgets.Add(widget); 17 document.Fields.Add(field); 18 } 19 20 //TextBox Field with text (and Cmyk black) 21 { 22 TextShape textShape = new TextShape( 250, page.Height - 75, "TextBox Field with text (and Cmyk black)", Font.Helvetica, 12 ); 23 page.VisualOverlay.Add( textShape ); 24 25 TextField field = new TextField("FieldName2"); 26 field.Value = "Hello World!"; 27 28 Widget widget = new Widget(10, page.Height - 75, 200, 15); 29 widget.TextColor = TallComponents.PDF.Colors.CmykColor.Black; 30 31 field.Widgets.Add(widget); 32 page.Widgets.Add(widget); 33 document.Fields.Add(field); 34 } 35 36 //TextBox Field with multiline text 37 { 38 TextShape textShape = new TextShape( 250, page.Height - 150, "TextBox Field with multiline text", Font.Helvetica, 12 ); 39 page.VisualOverlay.Add( textShape ); 40 41 TextField field = new TextField("FieldName3"); 42 field.Value = "Default text...\n...already included new-lines"; 43 field.ToolTip = "Tooltip for field 3"; 44 field.MappingName = "Mappingname3"; 45 46 field.MaxLength = 200; 47 field.Multiline = true; 48 field.RequiredMode = RequiredMode.Required; 49 50 Widget widget = new Widget(10, page.Height - 150, 200, 65); 51 52 widget.TextColor = System.Drawing.Color.Purple; 53 widget.BorderStyle = BorderStyle.Dashed; 54 widget.BorderColor = System.Drawing.Color.Red; 55 widget.BackgroundColor = System.Drawing.Color.Yellow; 56 57 widget.Font = TallComponents.PDF.Fonts.Font.TimesBoldItalic; 58 widget.FontSize = 9; 59 60 widget.HorizontalAlignment = HorizontalAlignment.Center; 61 62 field.Widgets.Add(widget); 63 page.Widgets.Add(widget); 64 document.Fields.Add(field); 65 } 66 67 //DropDownList Field -- no options but editable 68 { 69 TextShape textShape = new TextShape( 250, page.Height - 200, "DropDownList Field -- no options but editable", Font.Helvetica, 12 ); 70 page.VisualOverlay.Add( textShape ); 71 72 DropDownListField field = new DropDownListField("FieldName4"); 73 field.AllowTextEntry = true; 74 75 Widget widget = new Widget(10, page.Height - 200, 200, 15); 76 widget.BorderColor = System.Drawing.Color.Black; 77 78 field.Widgets.Add(widget); 79 page.Widgets.Add(widget); 80 document.Fields.Add(field); 81 } 82 83 //DropDownList Field -- with options 84 { 85 TextShape textShape = new TextShape( 250, page.Height - 225, "DropDownList Field -- with options", Font.Helvetica, 12 ); 86 page.VisualOverlay.Add( textShape ); 87 88 DropDownListField field = new DropDownListField("FieldName5"); 89 field.Options.Add(new ListOption("opt1")); 90 field.Options.Add(new ListOption("opt2")); 91 field.Options.Add(new ListOption("opt3")); 92 field.Value = "opt2"; 93 94 Widget widget = new Widget(10, page.Height - 225, 200, 15); 95 widget.BorderColor = System.Drawing.Color.Black; 96 widget.BorderStyle = BorderStyle.Inset; 97 98 field.Widgets.Add(widget); 99 page.Widgets.Add(widget); 100 document.Fields.Add(field); 101 } 102 103 //ListBox Field -- with options 104 { 105 TextShape textShape = new TextShape( 250, page.Height - 300, "ListBox Field -- with 6 options", Font.Helvetica, 12 ); 106 page.VisualOverlay.Add( textShape ); 107 108 ListBoxField field = new ListBoxField("FieldName6"); 109 field.Options.Add(new ListOption("1", "opt1")); 110 field.Options.Add(new ListOption("2", "opt2")); 111 field.Options.Add(new ListOption("3", "opt3")); 112 field.Options.Add(new ListOption("4", "opt4")); 113 field.Options.Add(new ListOption("5", "opt5")); 114 field.Options.Add(new ListOption("6", "opt6")); 115 field.ListBoxValue = new ListOption[1] { field.Options[1] }; 116 117 Widget widget = new Widget(10, page.Height - 300, 200, 50); 118 widget.BorderColor = System.Drawing.Color.DarkBlue; 119 120 field.Widgets.Add(widget); 121 page.Widgets.Add(widget); 122 document.Fields.Add(field); 123 } 124 125 126 //CheckBox Field -- unchecked 127 { 128 TextShape textShape = new TextShape( 250, page.Height - 350, "CheckBox Field -- unchecked", Font.Helvetica, 12 ); 129 page.VisualOverlay.Add( textShape ); 130 131 CheckBoxField field = new CheckBoxField("FieldName7"); 132 133 CheckBoxWidget widget = new CheckBoxWidget(10, page.Height - 350, 15, 15); 134 widget.BorderColor = System.Drawing.Color.Black; 135 widget.BorderStyle = BorderStyle.Inset; 136 137 field.Widgets.Add(widget); 138 page.Widgets.Add(widget); 139 document.Fields.Add(field); 140 } 141 142 //CheckBox Field -- checked, custom on-value 143 { 144 TextShape textShape = new TextShape( 250, page.Height - 375, "CheckBox Field -- checked, custom on-value", Font.Helvetica, 12 ); 145 page.VisualOverlay.Add( textShape ); 146 147 CheckBoxField field = new CheckBoxField("FieldName8"); 148 field.CheckBoxValue = CheckState.On; 149 150 CheckBoxWidget widget = new CheckBoxWidget(10, page.Height - 375, 15, 15); 151 widget.CheckMarkAppearance = CheckMarkAppearance.Check; 152 widget.TextColor = System.Drawing.Color.Purple; 153 widget.BorderColor = System.Drawing.Color.Green; 154 widget.BorderStyle = BorderStyle.Inset; 155 156 field.Widgets.Add(widget); 157 page.Widgets.Add(widget); 158 document.Fields.Add(field); 159 } 160 161 //PushButton Field -- default 162 { 163 TextShape textShape = new TextShape( 250, page.Height - 425, "PushButton Field -- default", Font.Helvetica, 12 ); 164 page.VisualOverlay.Add( textShape ); 165 166 PushButtonField field = new PushButtonField("FieldName9"); 167 168 PushButtonWidget widget = new PushButtonWidget(10, page.Height - 425, 100, 30); 169 widget.BackgroundColor = System.Drawing.Color.LightGray; 170 widget.BorderColor = System.Drawing.Color.Black; 171 widget.BorderStyle = BorderStyle.Beveled; 172 173 field.Widgets.Add(widget); 174 page.Widgets.Add(widget); 175 document.Fields.Add(field); 176 } 177 178 //PushButton Field -- with label 179 { 180 TextShape textShape = new TextShape( 250, page.Height - 474, "PushButton Field -- with label", Font.Helvetica, 12 ); 181 page.VisualOverlay.Add( textShape ); 182 183 PushButtonField field = new PushButtonField("FieldName10"); 184 185 PushButtonWidget widget = new PushButtonWidget(10, page.Height - 475, 200, 30); 186 widget.BackgroundColor = System.Drawing.Color.LightGray; 187 widget.BorderColor = System.Drawing.Color.Gray; 188 widget.BorderStyle = BorderStyle.Beveled; 189 190 widget.Label = "Push me!"; 191 192 field.Widgets.Add(widget); 193 page.Widgets.Add(widget); 194 document.Fields.Add(field); 195 196 //Show how a submit action must be included. 197 TallComponents.PDF.Actions.SubmitFormAction action = new TallComponents.PDF.Actions.SubmitFormAction(); 198 action.SubmitFormat = TallComponents.PDF.Actions.SubmitFormat.Xfdf; 199 action.Url = @"http://www.yourname.com/receiver.aspx"; 200 widget.MouseUpActions.Add( action ); 201 } 202 203 //PushButton Field -- with icon 204 { 205 TextShape textShape = new TextShape( 250, page.Height - 545, "PushButton Field -- with icon", Font.Helvetica, 12 ); 206 page.VisualOverlay.Add( textShape ); 207 208 PushButtonField field = new PushButtonField("FieldName11"); 209 210 PushButtonWidget widget = new PushButtonWidget(10, page.Height - 545, 100, 50); 211 widget.BackgroundColor = System.Drawing.Color.LightGray; 212 widget.BorderColor = System.Drawing.Color.Gray; 213 widget.BorderStyle = BorderStyle.Beveled; 214 215 widget.Layout = PushButtonLayout.IconOnly; 216 217 using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap( @"..\..\..\inputDocuments\logo_pdfkit.gif")) 218 { 219 widget.SetIcon(bitmap); 220 } 221 222 field.Widgets.Add(widget); 223 page.Widgets.Add(widget); 224 document.Fields.Add(field); 225 } 226 227 //RadioButtonField -- with 3 options 228 { 229 TextShape textShape = new TextShape( 250, page.Height - 600, "RadioButtonField -- with 3 options", Font.Helvetica, 12 ); 230 page.VisualOverlay.Add( textShape ); 231 232 RadioButtonField field = new RadioButtonField( "FieldName12"); 233 234 RadioButtonWidget widget = new RadioButtonWidget(10, page.Height - 600, 15, 15, "Option1"); 235 widget.BorderColor = System.Drawing.Color.Black; 236 field.Widgets.Add(widget); 237 page.Widgets.Add(widget); 238 239 widget = new RadioButtonWidget(35, page.Height - 600, 15, 15, "Option2"); 240 widget.BorderColor = System.Drawing.Color.Purple; 241 widget.BackgroundColor = System.Drawing.Color.Yellow; 242 widget.TextColor = System.Drawing.Color.Blue; 243 field.Widgets.Add(widget); 244 page.Widgets.Add(widget); 245 246 widget = new RadioButtonWidget(60, page.Height - 600, 15, 15, "Option3"); 247 widget.BorderColor = System.Drawing.Color.Green; 248 widget.BorderStyle = BorderStyle.Dashed; 249 widget.TextColor = System.Drawing.Color.Red; 250 field.Widgets.Add(widget); 251 page.Widgets.Add(widget); 252 253 field.RadioButtonValue = field.Options[1] as RadioButtonOption; 254 field.RadioButtonDefaultValue = field.Options[2] as RadioButtonOption; 255 document.Fields.Add(field); 256 } 257 258 //SignatureField -- unsigned 259 { 260 TextShape textShape = new TextShape( 250, page.Height - 650, "SignatureField -- unsigned", Font.Helvetica, 12 ); 261 page.VisualOverlay.Add( textShape ); 262 263 SignatureField field = new SignatureField("FieldName13"); 264 265 SignatureWidget widget = new SignatureWidget(10, page.Height - 650, 150, 40); 266 widget.BorderColor = System.Drawing.Color.Indigo; 267 268 field.Widgets.Add(widget); 269 page.Widgets.Add(widget); 270 document.Fields.Add(field); 271 } 272 273 //SignatureField -- signed 274 { 275 TextShape textShape = new TextShape( 250, page.Height - 700, "SignatureField -- signed", Font.Helvetica, 12 ); 276 page.VisualOverlay.Add( textShape ); 277 278 SignatureField field = new SignatureField("FieldName14"); 279 280 Pkcs12Store ks = null; 281 using (FileStream file = new FileStream( @"..\..\..\inputdocuments\ChrisSharp.pfx", FileMode.Open, FileAccess.Read)) 282 { 283 ks = new Pkcs12Store(file, "Sample"); 284 } 285 286 SignatureHandler handler = StandardSignatureHandler.Create(ks); 287 288 field.SignatureHandler = handler; 289 290 field.ContactInfo = "+31(0)77 4748677"; 291 field.Location = "The Netherlands"; 292 field.Reason = "I fully agree!"; 293 294 SignatureWidget widget = new SignatureWidget(10, page.Height - 700, 150, 40); 295 296 field.Widgets.Add(widget); 297 page.Widgets.Add(widget); 298 document.Fields.Add(field); 299 } 300 301 //PasswordField 302 { 303 TextShape textShape = new TextShape( 250, page.Height - 725, "PasswordField", Font.Helvetica, 12 ); 304 page.VisualOverlay.Add( textShape ); 305 306 PasswordField field = new PasswordField("FieldName15"); 307 308 Widget widget = new Widget(10, page.Height - 725, 100, 15); 309 widget.BorderColor = System.Drawing.Color.HotPink; 310 311 field.Widgets.Add(widget); 312 page.Widgets.Add(widget); 313 document.Fields.Add(field); 314 } 315 316 // write the modified document to disk, note: signing requires read-write file access 317 using ( FileStream outFile = new FileStream( @"..\..\createformfields.pdf", FileMode.Create, FileAccess.ReadWrite ) ) 318 { 319 document.Write( outFile ); 320 }

VB.NET code sample

1 'New document 2 Dim document As New Document() 3 4 Dim page As New Page(PageSize.A4) 5 document.Pages.Add(page) 6 7 'TextBox Field with all default values 8 Dim textShape1 As New TextShape(250, page.Height - 50, "TextBox Field with all default values", Font.Helvetica, 12) 9 page.VisualOverlay.Add(textShape1) 10 11 Dim field1 As New TextField("FieldName1") 12 Dim widget1 As New Widget(10, page.Height - 50, 200, 15) 13 14 field1.Widgets.Add(widget1) 15 page.Widgets.Add(widget1) 16 document.Fields.Add(field1) 17 18 'TextBox Field with text (and Cmyk black) 19 Dim textShape2 As New TextShape(250, page.Height - 75, "TextBox Field with text (and Cmyk black)", Font.Helvetica, 12) 20 page.VisualOverlay.Add(textShape2) 21 22 Dim field2 As New TextField("FieldName2") 23 field2.Value = "Hello World!" 24 25 Dim widget2 As New Widget(10, page.Height - 75, 200, 15) 26 widget2.TextColor = TallComponents.PDF.Colors.CmykColor.Black 27 28 field2.Widgets.Add(widget2) 29 page.Widgets.Add(widget2) 30 document.Fields.Add(field2) 31 32 'TextBox Field with multiline text 33 Dim textShape3 As New TextShape(250, page.Height - 150, "TextBox Field with multiline text", Font.Helvetica, 12) 34 page.VisualOverlay.Add(textShape3) 35 36 Dim field3 As New TextField("FieldName3") 37 field3.Value = "Default text..." & Environment.NewLine & "...already included new-lines" 38 field3.ToolTip = "Tooltip for field 3" 39 field3.MappingName = "Mappingname3" 40 41 field3.MaxLength = 200 42 field3.Multiline = True 43 field3.RequiredMode = RequiredMode.Required 44 45 Dim widget3 As New Widget(10, page.Height - 150, 200, 65) 46 47 widget3.TextColor = System.Drawing.Color.Purple 48 widget3.BorderStyle = BorderStyle.Dashed 49 widget3.BorderColor = System.Drawing.Color.Red 50 widget3.BackgroundColor = System.Drawing.Color.Yellow 51 52 widget3.Font = TallComponents.PDF.Fonts.Font.TimesBoldItalic 53 widget3.FontSize = 9 54 55 widget3.HorizontalAlignment = HorizontalAlignment.Center 56 57 field3.Widgets.Add(widget3) 58 page.Widgets.Add(widget3) 59 document.Fields.Add(field3) 60 61 'DropDownList Field -- no options but editable 62 Dim textShape4 As New TextShape(250, page.Height - 200, "DropDownList Field -- no options but editable", Font.Helvetica, 12) 63 page.VisualOverlay.Add(textShape4) 64 65 Dim field4 As New DropDownListField("FieldName4") 66 field4.AllowTextEntry = True 67 68 Dim widget4 As New Widget(10, page.Height - 200, 200, 15) 69 widget4.BorderColor = System.Drawing.Color.Black 70 71 field4.Widgets.Add(widget4) 72 page.Widgets.Add(widget4) 73 document.Fields.Add(field4) 74 75 'DropDownList Field -- with options 76 Dim textShape5 As New TextShape(250, page.Height - 225, "DropDownList Field -- with options", Font.Helvetica, 12) 77 page.VisualOverlay.Add(textShape5) 78 79 Dim field5 As New DropDownListField("FieldName5") 80 field5.Options.Add(New ListOption("opt1")) 81 field5.Options.Add(New ListOption("opt2")) 82 field5.Options.Add(New ListOption("opt3")) 83 field5.Value = "opt2" 84 85 Dim widget5 As New Widget(10, page.Height - 225, 200, 15) 86 widget5.BorderColor = System.Drawing.Color.Black 87 widget5.BorderStyle = BorderStyle.Inset 88 89 field5.Widgets.Add(widget5) 90 page.Widgets.Add(widget5) 91 document.Fields.Add(field5) 92 93 'ListBox Field -- with options 94 Dim textShape6 As New TextShape(250, page.Height - 300, "ListBox Field -- with 6 options", Font.Helvetica, 12) 95 page.VisualOverlay.Add(textShape6) 96 97 Dim field6 As New ListBoxField("FieldName6") 98 field6.Options.Add(New ListOption("1", "opt1")) 99 field6.Options.Add(New ListOption("2", "opt2")) 100 field6.Options.Add(New ListOption("3", "opt3")) 101 field6.Options.Add(New ListOption("4", "opt4")) 102 field6.Options.Add(New ListOption("5", "opt5")) 103 field6.Options.Add(New ListOption("6", "opt6")) 104 field6.ListBoxValue = New ListOption(0) {field6.Options(1)} 105 106 Dim widget6 As New Widget(10, page.Height - 300, 200, 50) 107 widget6.BorderColor = System.Drawing.Color.DarkBlue 108 109 field6.Widgets.Add(widget6) 110 page.Widgets.Add(widget6) 111 document.Fields.Add(field6) 112 113 114 'CheckBox Field -- unchecked 115 Dim textShape7 As New TextShape(250, page.Height - 350, "CheckBox Field -- unchecked", Font.Helvetica, 12) 116 page.VisualOverlay.Add(textShape7) 117 118 Dim field7 As New CheckBoxField("FieldName7") 119 120 Dim widget7 As New CheckBoxWidget(10, page.Height - 350, 15, 15) 121 widget7.BorderColor = System.Drawing.Color.Black 122 widget7.BorderStyle = BorderStyle.Inset 123 124 field7.Widgets.Add(widget7) 125 page.Widgets.Add(widget7) 126 document.Fields.Add(field7) 127 128 'CheckBox Field -- checked, custom on-value 129 Dim textShape8 As New TextShape(250, page.Height - 375, "CheckBox Field -- checked, custom on-value", Font.Helvetica, 12) 130 page.VisualOverlay.Add(textShape8) 131 132 Dim field8 As New CheckBoxField("FieldName8") 133 field8.CheckBoxValue = CheckState.[On] 134 135 Dim widget8 As New CheckBoxWidget(10, page.Height - 375, 15, 15) 136 widget8.CheckMarkAppearance = CheckMarkAppearance.Check 137 widget8.TextColor = System.Drawing.Color.Purple 138 widget8.BorderColor = System.Drawing.Color.Green 139 widget8.BorderStyle = BorderStyle.Inset 140 141 field8.Widgets.Add(widget8) 142 page.Widgets.Add(widget8) 143 document.Fields.Add(field8) 144 145 'PushButton Field -- default 146 Dim textShape9 As New TextShape(250, page.Height - 425, "PushButton Field -- default", Font.Helvetica, 12) 147 page.VisualOverlay.Add(textShape9) 148 149 Dim field9 As New PushButtonField("FieldName9") 150 151 Dim widget9 As New PushButtonWidget(10, page.Height - 425, 100, 30) 152 widget9.BackgroundColor = System.Drawing.Color.LightGray 153 widget9.BorderColor = System.Drawing.Color.Black 154 widget9.BorderStyle = BorderStyle.Beveled 155 156 field9.Widgets.Add(widget9) 157 page.Widgets.Add(widget9) 158 document.Fields.Add(field9) 159 160 'PushButton Field -- with label 161 Dim textShape10 As New TextShape(250, page.Height - 474, "PushButton Field -- with label", Font.Helvetica, 12) 162 page.VisualOverlay.Add(textShape10) 163 164 Dim field10 As New PushButtonField("FieldName10") 165 166 Dim widget10 As New PushButtonWidget(10, page.Height - 475, 200, 30) 167 widget10.BackgroundColor = System.Drawing.Color.LightGray 168 widget10.BorderColor = System.Drawing.Color.Gray 169 widget10.BorderStyle = BorderStyle.Beveled 170 171 widget10.Label = "Push me!" 172 173 field10.Widgets.Add(widget10) 174 page.Widgets.Add(widget10) 175 document.Fields.Add(field10) 176 177 'Show how a submit action must be included. 178 Dim action As New TallComponents.PDF.Actions.SubmitFormAction() 179 action.SubmitFormat = TallComponents.PDF.Actions.SubmitFormat.Xfdf 180 action.Url = "http://www.yourname.com/receiver.aspx" 181 widget10.MouseUpActions.Add(action) 182 183 'PushButton Field -- with icon 184 Dim textShape11 As New TextShape(250, page.Height - 545, "PushButton Field -- with icon", Font.Helvetica, 12) 185 page.VisualOverlay.Add(textShape11) 186 187 Dim field11 As New PushButtonField("FieldName11") 188 189 Dim widget11 As New PushButtonWidget(10, page.Height - 545, 100, 50) 190 widget11.BackgroundColor = System.Drawing.Color.LightGray 191 widget11.BorderColor = System.Drawing.Color.Gray 192 widget11.BorderStyle = BorderStyle.Beveled 193 194 widget11.Layout = PushButtonLayout.IconOnly 195 196 Using bitmap As New System.Drawing.Bitmap("..\..\..\inputDocuments\logo_pdfkit.gif") 197 widget11.SetIcon(bitmap) 198 End Using 199 200 field11.Widgets.Add(widget11) 201 page.Widgets.Add(widget11) 202 document.Fields.Add(field11) 203 204 'RadioButtonField -- with 3 options 205 Dim textShape12 As New TextShape(250, page.Height - 600, "RadioButtonField -- with 3 options", Font.Helvetica, 12) 206 page.VisualOverlay.Add(textShape12) 207 208 Dim field12 As New RadioButtonField("FieldName12") 209 210 Dim widget12 As New RadioButtonWidget(10, page.Height - 600, 15, 15, "Option1") 211 widget12.BorderColor = System.Drawing.Color.Black 212 field12.Widgets.Add(widget12) 213 page.Widgets.Add(widget12) 214 215 widget12 = New RadioButtonWidget(35, page.Height - 600, 15, 15, "Option2") 216 widget12.BorderColor = System.Drawing.Color.Purple 217 widget12.BackgroundColor = System.Drawing.Color.Yellow 218 widget12.TextColor = System.Drawing.Color.Blue 219 field12.Widgets.Add(widget12) 220 page.Widgets.Add(widget12) 221 222 widget12 = New RadioButtonWidget(60, page.Height - 600, 15, 15, "Option3") 223 widget12.BorderColor = System.Drawing.Color.Green 224 widget12.BorderStyle = BorderStyle.Dashed 225 widget12.TextColor = System.Drawing.Color.Red 226 field12.Widgets.Add(widget12) 227 page.Widgets.Add(widget12) 228 229 field12.RadioButtonValue = TryCast(field12.Options(1), RadioButtonOption) 230 field12.RadioButtonDefaultValue = TryCast(field12.Options(2), RadioButtonOption) 231 document.Fields.Add(field12) 232 233 'SignatureField -- unsigned 234 Dim textShape13 As New TextShape(250, page.Height - 650, "SignatureField -- unsigned", Font.Helvetica, 12) 235 page.VisualOverlay.Add(textShape13) 236 237 Dim field13 As New SignatureField("FieldName13") 238 239 Dim widget13 As New SignatureWidget(10, page.Height - 650, 150, 40) 240 widget13.BorderColor = System.Drawing.Color.Indigo 241 242 field13.Widgets.Add(widget13) 243 page.Widgets.Add(widget13) 244 document.Fields.Add(field13) 245 246 'SignatureField -- signed 247 Dim textShape14 As New TextShape(250, page.Height - 700, "SignatureField -- signed", Font.Helvetica, 12) 248 page.VisualOverlay.Add(textShape14) 249 250 Dim field14 As New SignatureField("FieldName14") 251 252 Dim ks As Pkcs12Store = Nothing 253 Using file As New FileStream("..\..\..\inputdocuments\ChrisSharp.pfx", FileMode.Open, FileAccess.Read) 254 ks = New Pkcs12Store(file, "Sample") 255 End Using 256 257 Dim handler As SignatureHandler = StandardSignatureHandler.Create(ks) 258 259 field14.SignatureHandler = handler 260 261 field14.ContactInfo = "+31(0)77 4748677" 262 field14.Location = "The Netherlands" 263 field14.Reason = "I fully agree!" 264 265 Dim widget14 As New SignatureWidget(10, page.Height - 700, 150, 40) 266 267 field14.Widgets.Add(widget14) 268 page.Widgets.Add(widget14) 269 document.Fields.Add(field14) 270 271 'PasswordField 272 Dim textShape15 As New TextShape(250, page.Height - 725, "PasswordField", Font.Helvetica, 12) 273 page.VisualOverlay.Add(textShape15) 274 275 Dim field15 As New PasswordField("FieldName15") 276 277 Dim widget15 As New Widget(10, page.Height - 725, 100, 15) 278 widget15.BorderColor = System.Drawing.Color.HotPink 279 280 field15.Widgets.Add(widget15) 281 page.Widgets.Add(widget15) 282 document.Fields.Add(field15) 283 284 ' write the modified document to disk, note: signing requires read-write file access 285 Using outFile As New FileStream("..\..\createformfields.pdf", FileMode.Create, FileAccess.ReadWrite) 286 document.Write(outFile) 287 End Using