How can I help you?
Import and Export Form Data in .NET MAUI PDF Viewer (SfPdfViewer)
25 Mar 20263 minutes to read
The SfPdfViewer allows you to import form data into a PDF document and export filled form data from it. This is useful for pre-populating forms, backing up responses, or transferring data between systems.
Supported data formats
The following formats are supported for both import and export:
| Format | Description |
|---|---|
| XFDF | XML Forms Data Format — standard format compatible with most PDF viewers. |
| FDF | Forms Data Format — standard format compatible with most PDF viewers. |
| JSON | Custom format, compatible with Syncfusion PDF Viewers (WPF, Flutter, JavaScript, etc.). |
| XML | Custom format, compatible with Syncfusion PDF Viewers (WPF, Flutter, JavaScript, etc.). |
The required format can be selected from the DataFormat enumeration.
NOTE
XFDF and FDF are standard formats compatible with global PDF viewers. JSON and XML are Syncfusion-specific formats for cross-platform use within Syncfusion products only.
Import form data
Use the ImportFormData method to populate form fields from an external data file. Pass the file stream and the data format as parameters.
The following example imports form data from an XFDF file stored in the application’s data directory.
void ImportFormData()
{
string fileName = Path.Combine(FileSystem.Current.AppDataDirectory, "FormDataInfo.xfdf");
Stream inputFileStream = File.OpenRead(fileName);
inputFileStream.Position = 0;
pdfViewer.ImportFormData(inputFileStream, Syncfusion.Pdf.Parsing.DataFormat.XFdf);
}To continue importing even if the file contains errors, pass true for the continueImportOnError parameter.
pdfViewer.ImportFormData(inputFileStream, Syncfusion.Pdf.Parsing.DataFormat.XFdf, true);Export form data
Use the ExportFormData method to write the current form field values to a file. Pass an empty writable stream and the desired format.
The following example exports form data to an XFDF file in the application’s data directory.
void ExportFormData()
{
string targetFile = Path.Combine(FileSystem.Current.AppDataDirectory, "ExportedFormData.xfdf");
FileStream fileStream = File.Create(targetFile);
pdfViewer.ExportFormData(fileStream, Syncfusion.Pdf.Parsing.DataFormat.XFdf);
}