Articles in this section
Category / Section

How to convert PDF to fillable PDF form using C# and VB.NET in WinForms?

6 mins read

The Syncfusion Essential® PDF is a .NET PDF Library used to create, read, and edit PDF documents. Using this library, you can convert PDF to fillable PDF form using C# and VB.NET.

Steps to convert PDF to fillable PDF form 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 Program.cs file.

C#

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

 

VB.NET

Imports Syncfusion.Pdf
Imports Syncfusion.Pdf.Graphics
Imports Syncfusion.Pdf.Parsing
Imports Syncfusion.Pdf.Interactive
Imports System.Drawing

 

 

  1. Use the following code snippet to convert PDF to fillable PDF form.

C#

//Load the existing PDF document
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf");
//Create the form if the form does not exist in the loaded document
if (loadedDocument.Form == null)
    loadedDocument.CreateForm();
//Load the page
PdfLoadedPage loadedPage = loadedDocument.Pages[0] as PdfLoadedPage;
 
//Set the standard font
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 16);
//Draw the string      
loadedPage.Graphics.DrawString("Job Application", font, PdfBrushes.Black, new PointF(250, 30));
font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
 
loadedPage.Graphics.DrawString("Name", font, PdfBrushes.Black, new PointF(30, 50));
//Create a text box field for name
PdfTextBoxField textBoxField1 = new PdfTextBoxField(loadedPage, "Name");
textBoxField1.Bounds = new RectangleF(30, 70, 200, 20);
textBoxField1.ToolTip = "Name";
loadedDocument.Form.Fields.Add(textBoxField1);
 
loadedPage.Graphics.DrawString("Email address", font, PdfBrushes.Black, new PointF(30, 110));
//Create a text box field for email address
PdfTextBoxField textBoxField3 = new PdfTextBoxField(loadedPage, "Email address");
textBoxField3.Bounds = new RectangleF(30, 130, 200, 20);
textBoxField3.ToolTip = "Email address";
loadedDocument.Form.Fields.Add(textBoxField3);
 
loadedPage.Graphics.DrawString("Gender", font, PdfBrushes.Black, new PointF(30, 180));
//Create radio button for gender
PdfRadioButtonListField employeesRadioList = new PdfRadioButtonListField(loadedPage, "Gender");
loadedDocument.Form.Fields.Add(employeesRadioList);
loadedPage.Graphics.DrawString("Male", font, PdfBrushes.Black, new PointF(60, 200));
PdfRadioButtonListItem radioButtonItem1 = new PdfRadioButtonListItem("Male");
 
 
 
radioButtonItem1.Bounds = new RectangleF(30, 200, 20, 20);
loadedPage.Graphics.DrawString("Female", font, PdfBrushes.Black, new PointF(160, 200));
PdfRadioButtonListItem radioButtonItem2 = new PdfRadioButtonListItem("Female");
radioButtonItem2.Bounds = new RectangleF(130, 200, 20, 20);
employeesRadioList.Items.Add(radioButtonItem1);
employeesRadioList.Items.Add(radioButtonItem2);
 
loadedPage.Graphics.DrawString("Which position you are applying for?", font, PdfBrushes.Black, new PointF(30, 240));
//Create combo box for position
PdfComboBoxField comboBox = new PdfComboBoxField(loadedPage, "JobTitle");
comboBox.Bounds = new RectangleF(30, 260, 100, 20);
comboBox.BorderColor = new PdfColor(Color.Gray);
comboBox.ToolTip = "Job Title";
comboBox.Items.Add(new PdfListFieldItem("Development", "Development"));
comboBox.Items.Add(new PdfListFieldItem("Support", "Support"));
comboBox.Items.Add(new PdfListFieldItem("Documentation", "Documentation"));
loadedDocument.Form.Fields.Add(comboBox);
 
//Save the document
loadedDocument.Save("Form.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("Form.pdf");

 

VB.NET

'Load the existing PDF document
Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Input.pdf")
'Create the form if the form does not exist in the loaded document
If loadedDocument.Form Is Nothing Then loadedDocument.CreateForm()
'Load the page
Dim loadedPage As PdfLoadedPage = TryCast(loadedDocument.Pages(0), PdfLoadedPage)
 
'Set the standard font
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 16)
'Draw the string     
loadedPage.Graphics.DrawString("Job Application", font, PdfBrushes.Black, New PointF(250, 30))
font = New PdfStandardFont(PdfFontFamily.Helvetica, 12)
 
loadedPage.Graphics.DrawString("Name", font, PdfBrushes.Black, New PointF(30, 50))
'Create a text box field for name
Dim textBoxField1 As PdfTextBoxField = New PdfTextBoxField(loadedPage, "Name")
textBoxField1.Bounds = New RectangleF(30, 70, 200, 20)
textBoxField1.ToolTip = "Name"
loadedDocument.Form.Fields.Add(textBoxField1)
loadedPage.Graphics.DrawString("Email address", font, PdfBrushes.Black, New PointF(30, 110))
'Create a text box field for email address
Dim textBoxField3 As PdfTextBoxField = New PdfTextBoxField(loadedPage, "Email address")
textBoxField3.Bounds = New RectangleF(30, 130, 200, 20)
textBoxField3.ToolTip = "Email address"
loadedDocument.Form.Fields.Add(textBoxField3)
 
loadedPage.Graphics.DrawString("Gender", font, PdfBrushes.Black, New PointF(30, 180))
'Create radio button for gender
Dim employeesRadioList As PdfRadioButtonListField = New PdfRadioButtonListField(loadedPage, "Gender")
loadedDocument.Form.Fields.Add(employeesRadioList)
loadedPage.Graphics.DrawString("Male", font, PdfBrushes.Black, New PointF(60, 200))
Dim radioButtonItem1 As PdfRadioButtonListItem = New PdfRadioButtonListItem("Male")
radioButtonItem1.Bounds = New RectangleF(30, 200, 20, 20)
loadedPage.Graphics.DrawString("Female", font, PdfBrushes.Black, New PointF(160, 200))
Dim radioButtonItem2 As PdfRadioButtonListItem = New PdfRadioButtonListItem("Female")
radioButtonItem2.Bounds = New RectangleF(130, 200, 20, 20)
employeesRadioList.Items.Add(radioButtonItem1)
employeesRadioList.Items.Add(radioButtonItem2)
 
loadedPage.Graphics.DrawString("Which position you are applying for?", font, PdfBrushes.Black, New PointF(30, 240))
'Create combo box for position
Dim comboBox As PdfComboBoxField = New PdfComboBoxField(loadedPage, "JobTitle")
comboBox.Bounds = New RectangleF(30, 260, 100, 20)
comboBox.BorderColor = New PdfColor(Color.Gray)
comboBox.ToolTip = "Job Title"
comboBox.Items.Add(New PdfListFieldItem("Development", "Development"))
comboBox.Items.Add(New PdfListFieldItem("Support", "Support"))
comboBox.Items.Add(New PdfListFieldItem("Documentation", "Documentation"))
loadedDocument.Form.Fields.Add(comboBox)
 
'Save the document
loadedDocument.Save("Form.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("Form.pdf")

 

Download the work sample from PDFtoFillablePDFSample.zip.

By executing the program, you will get the PDF document as follows. Output document screenshot

Take a moment to peruse the documentation, where you will find the options like creating a form in new PDF document, modifying existing form fields, 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, adding annotation to PDF, and more with code examples.

Click here to learn more about Syncfusion® PDF forms.

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 this link to learn about generating and registering Syncfusion® license key in your application to use the components without trail message.

 

 

Conclusion

I hope you enjoyed learning about how to convert PDF to fillable PDF form using C# and VB.NET.

You can refer to our WinForms PDF feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms PDF example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!
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