Articles in this section
Category / Section

How to move form field to the new location in an existing PDF using C# and VB.NET

2 mins read

Syncfusion Essential PDF is a .NET PDF library used to create, read, and edit PDF documents. Using this library, you can move form field to the new location in an existing PDF using C# and VB.NET.

Steps to move form field to the new location in an existing PDF programmatically:

  1. Create a new C# console application project. Create a console application project
  2. Install the Syncfusion.Pdf.WinForms NuGet package as reference to your .NET Framework application from NuGet.org. NuGet package reference screenshot
  3. Include the following namespaces in the Program.cs file.

C#

using Syncfusion.Pdf.Parsing;
using System.Drawing;

 

VB.NET

Imports Syncfusion.Pdf.Graphics
Imports System.Drawing
  1. Use the following code snippet to move form field to the new location in an existing PDF document.

C#

//Load the PDF document
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Form.pdf");
//Get the loaded form
PdfLoadedForm loadedForm = loadedDocument.Form;
//Get the loaded form field and modify the properties
PdfLoadedTextBoxField loadedTextBoxField = loadedForm.Fields[0] as PdfLoadedTextBoxField;
RectangleF newBounds = new RectangleF(50, 70, 100, 20);
//Set the new location to the existing textbox field
loadedTextBoxField.Bounds = newBounds;
loadedTextBoxField.Text = "Simons Bistro";
//Save the document
loadedDocument.Save("ModifiedForm.pdf");
//Close the document
loadedDocument.Close(true);
//This will open the PDF file so, the result will be seen in default PDF Viewer 
Process.Start("ModifiedForm.pdf");

 

VB.NET

'Load the PDF document
Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Form.pdf")
'Get the loaded form
Dim loadedForm As PdfLoadedForm = loadedDocument.Form
'Get the loaded form field and modify the properties
Dim loadedTextBoxField As PdfLoadedTextBoxField = TryCast(loadedForm.Fields(0), PdfLoadedTextBoxField)
Dim newBounds As RectangleF = New RectangleF(50, 70, 100, 20)
'Set the new location to the existing textbox field
loadedTextBoxField.Bounds = newBounds
loadedTextBoxField.Text = "Simons Bistro"
'Save the document
loadedDocument.Save("ModifiedForm.pdf")
'Close the document
loadedDocument.Close(True)
'This will open the PDF file so, the result will be seen in default PDF Viewer 
Process.Start("ModifiedForm.pdf")

 

A complete working sample can be downloaded from PDFFormSample.zip.

Take a moment to peruse the documentation, where you can find options like creating a new PDF form, filling form fields, removing editing capability, removing form fields, importing FDF file to PDF, export PDF file to FDF, adding actions to form fields, and features like XFA Form and annotation with code examples.

Refer here to explore PDF forms in Syncfusion Essential PDF.

Note:

Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion license key in your application to use the components without trail message.

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied