Articles in this section
Category / Section

How to import and export PDF form data in C# and VB.NET

3 mins read

Syncfusion Essential PDF is a .NET PDF library used to create, read, and edit PDF documents. Using this library, you can import and export PDF form data using C# and VB.NET.

Steps to import and export PDF form data programmatically:

  1. Create a new C# Windows Forms application project. Create new windows forms application
  2. Install the Syncfusion.Pdf.WinForms NuGet package as reference to your .NET Framework application from NuGet.org. Install nuget packages
  3. Include the following namespaces in the Form1.Designer.cs file.

C#

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

 

VB.NET

Imports Syncfusion.Pdf
Imports Syncfusion.Pdf.Interactive
Imports Syncfusion.Pdf.Graphics
Imports Syncfusion.Pdf.Parsing

 

  1. Use the following code snippet to import and export PDF form data.

C#

//Load an existing document
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(@"../../Input/FormFill.pdf");
//Load an existing form
PdfLoadedForm loadedForm = loadedDocument.Form;
MemoryStream memoryStream = new MemoryStream();
//Export the existing PDF document to FDF file
loadedForm.ExportData("Export.fdf", DataFormat.Fdf, @"AcroForm1");
//Close the document
loadedDocument.Close(true);
//Load an existing document
PdfLoadedDocument loadedDocument1 = new PdfLoadedDocument(@"../../Input/Form.pdf");
//Load an existing form
PdfLoadedForm loadedForm1 = loadedDocument1.Form;
//Load the FDF file
FileStream stream1 = new FileStream(@"Export.fdf", FileMode.Open);
//Import the FDF stream
loadedForm1.ImportDataFDF(stream1, true);
loadedDocument1.Save(@"Output.pdf");
//Close the document
loadedDocument1.Close(true);

 

VB.NET

'Load an existing document
Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("../../Input/FormFill.pdf")
'Load an existing form
Dim loadedForm As PdfLoadedForm = loadedDocument.Form
Dim memoryStream As MemoryStream = New MemoryStream
'Export the existing PDF document to FDF file
loadedForm.ExportData("Export.fdf", DataFormat.Fdf, "AcroForm1")
'Close the document
loadedDocument.Close(True)
Dim loadedDocument1 As PdfLoadedDocument = New PdfLoadedDocument("../../Input/Form.pdf")
Dim loadedForm1 As PdfLoadedForm = loadedDocument1.Form
Dim stream1 As FileStream = New FileStream("Export.fdf", FileMode.Open)
'Import the FDF stream
loadedForm1.ImportDataFDF(stream1, True)
loadedDocument1.Save("Output.pdf")
'Close the document
loadedDocument1.Close(True)

 

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

By executing the program, you will get the PDF document as follows. Screenshot of output pdf file

Take a moment to peruse the documentation for working with forms, where you will find other options like filling, removing form fields in PDF document, and adding actions to form fields.

Refer here to explore the rich set of Syncfusion Essential PDF features.

An Online sample link to filling form fields into PDF document.

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