VB.NET PDF: How to HTML5 PDF Viewer PDF Create PDF Export File & Page Process PDF Read PDF Write Form Process Document Protect Annotation & Drawing PDF Print WPF PDF Viewer Work with Other SDKs Barcode Read Barcode Create OCR Twain
Field: Insert, Delete, Update Field
  |  
Home ›› XDoc.PDF ›› VB.NET PDF: Insert, Delete, Update Field

VB.NET PDF - Insert, Delete and Update Field in VB.NET


How to Insert, Delete and Update Fields in PDF Document with VB.NET Demo Code




Overview



Field inserting, deletion and update is the most basic field edit function. By using RaterEdge .NET PDF package, you can add form fields to existing pdf files, delete or remove form field in PDF page and update PDF field in VB.NET application. VB.NET sample codes are provided below to help you finish these task.




VB.NET DLLs: Insert, Delete and Update Field



In order to run the sample code, the following steps would be necessary.


Add necessary references:


  RasterEdge.Imaging.Basic.dll


  RasterEdge.Imaging.Basic.Codec.dll


  RasterEdge.Imaging.Drawing.dll


  RasterEdge.Imaging.Font.dll


  RasterEdge.Imaging.Processing.dll


  RasterEdge.XDoc.Raster.dll


  RasterEdge.XDoc.Raster.Core.dll


  RasterEdge.XDoc.PDF.dll


Use corresponding namespaces;


  using RasterEdge.Imaging.Basic;


  using RasterEdge.XDoc.PDF;




VB.NET Demo Code: Add Form Fields to an Existing PDF File



The demo code below can help you to add form fields to PDF file in VB.NET class




Dim inputFilePath As String = Program.RootPath + "\\" + "empty.pdf"
Dim outputFilePath As String = Program.RootPath + "\\" + "Output.pdf"

Dim fields As List(Of BaseFormField) = New List(Of BaseFormField)

' add a radio button field with default setting
Dim field1 As AFRadioButton = New AFRadioButton("AF_RadioButton_01")
field1.PageIndex = 0
field1.Position = New PointF(100.0F, 100.0F)
fields.Add(field1)

' add a checkbox field with default setting
Dim field2 As AFCheckBox = New AFCheckBox("AF_CheckBox_01")
field2.PageIndex = 0
field2.Position = New PointF(300.0F, 100.0F)
fields.Add(field2)

' add a checkbox field with default setting
Dim field3 As AFTextBox = New AFTextBox("AF_TextBox_01")
field3.PageIndex = 0
field3.Position = New PointF(100.0F, 300.0F)
fields.Add(field3)

' add a list box field with default setting
Dim field4 As AFListBox = New AFListBox("AF_ListBox_01")
field4.PageIndex = 0
field4.Position = New PointF(100.0F, 500.0F)
field4.Items = New String() {"Item 1", "Item 2", "Item 3", "Item 4"}
fields.Add(field4)

' add a combo box field with default setting
Dim field5 As AFComboBox = New AFComboBox("AF_ComboBox_01")
field5.PageIndex = 0
field5.Position = New PointF(300.0F, 500.0F)
field5.Items = New String() {"Item 1", "Item 2", "Item 3", "Item 4"}
fields.Add(field5)

' add a button field with default setting
Dim field6 As AFButton = New AFButton("AF_Button_01")
field6.PageIndex = 0
field6.Position = New PointF(100.0F, 700.0F)
fields.Add(field6)

' add fields to the input file
PDFFormHandler.AddFormFields(inputFilePath, fields, outputFilePath)





VB.NET Demo Code: Delete a Form Field in PDF Page



This is VB.NET sample code for deleting PDF document form field.




Dim inputFilePath As String = Program.RootPath + "\\" + "1_AF.pdf"
Dim outputFilePath As String = Program.RootPath + "\\" + "output.pdf"

' remove a field by name and output the new document
Dim fieldName As String = "AF_RadioButton_01"
Dim errCode As Integer = PDFFormHandler.RemoveFormField(inputFilePath, fieldName, outputFilePath)
If errCode = 0 Then
    Console.WriteLine("Success")
Else
    Console.WriteLine("Failed")
End If