Import XFDF annotation data to PDFs in C# .NET
An XML Forms Data Format (XFDF) file stores annotation and form field data from PDF documents. It contains the annotation structure and the values submitted to it.
Download sampleImporting XFDF data from a file
To import the annotation data from a file, use the ImportXFDFDataFromFile method with the following required parameters:
FilePath— The file path of the XFDF file.ImportFormFields— A Boolean value that specifies whether to import the form field data.ImportAnnotations— A Boolean value that specifies whether to import the annotation data.
The example below imports the annotations from an XFDF file:
Register the SDK license before running annotation operations. For setup details, refer to the getting started with .NET SDK guide.
using GdPicture14;
LicenseManager license = new LicenseManager();license.RegisterKEY("");using GdPicturePDF gdpicturePDF = new GdPicturePDF();gdpicturePDF.LoadFromFile(@"input.pdf");gdpicturePDF.ImportXFDFDataFromFile(@"input.xfdf", true, true);gdpicturePDF.SaveToFile(@"output.pdf");Register the SDK license before running annotation operations. For setup details, refer to the getting started with .NET SDK guide.
Imports System.IOImports GdPicture14
Dim license As LicenseManager = New LicenseManager()license.RegisterKEY("")Using gdpicturePDF As GdPicturePDF = New GdPicturePDF() gdpicturePDF.LoadFromFile("input.pdf") gdpicturePDF.ImportXFDFDataFromFile("input.xfdf", True, True) gdpicturePDF.SaveToFile("output.pdf")End UsingImporting XFDF data from a database
To import the annotation data from a database, save the XFDF information from the database as a Stream object, and then use the ImportXFDFDataFromStream method with the following required parameters:
Stream— TheStreamobject containing XFDF information.ImportFormFields— A Boolean value that specifies whether to import the form field data.ImportAnnotations— A Boolean value that specifies whether to import the annotation data.
The example below imports the annotations from a Stream object containing XFDF information:
using GdPicturePDF gdpicturePDFFromStream = new GdPicturePDF();gdpicturePDFFromStream.LoadFromFile(@"input.pdf");// Open the XFDF data as a stream. In your application, use the stream that holds the XFDF data from your database.using FileStream xfdfStream = File.OpenRead(@"input.xfdf");gdpicturePDFFromStream.ImportXFDFDataFromStream(xfdfStream, true, true);gdpicturePDFFromStream.SaveToFile(@"output_stream.pdf");Using gdpicturePDFFromStream As GdPicturePDF = New GdPicturePDF() gdpicturePDFFromStream.LoadFromFile("input.pdf") ' Open the XFDF data as a stream. In your application, use the stream that holds the XFDF data from your database. Using xfdfStream As FileStream = File.OpenRead("input.xfdf") gdpicturePDFFromStream.ImportXFDFDataFromStream(xfdfStream, True, True) End Using gdpicturePDFFromStream.SaveToFile("output_stream.pdf")End Using