Import and Export
The methods for importing and exporting XFDF annotations allow users to save and restore annotations and form data without altering the original PDF document, facilitating the sharing and processing of documents across different editors or platforms.
Import Annotations
When importing annotations via XFDF, a temporary file directory is created. It is necessary to specify both the XFDF path and the temporary file path during the annotation import.
This example shows how to import annotations:
//the path of xfdf
String xfdfPath = context.getCacheDir().getAbsolutePath() + "/xfdf/exportXFDF.xfdf";
//the transfer path of audio and video files
String tmpxfdfPath = context.getCacheDir().getAbsolutePath() + "/tmp";
document.importAnnotations(xfdfPath,tmpxfdfPath);
// the path of xfdf
val xfdfPath: String = "${context.cacheDir.absolutePath}/xfdf/exportXFDF.xfdf"
// the transfer path of audio and video files
val tmpxfdfPath: String = "${context.cacheDir.absolutePath}/tmp"
// Please make sure the 'tmpxfdfPath' folder exists
document.importAnnotations(xfdfPath, tmpxfdfPath)
Export Annotations
When exporting annotations via XFDF, a temporary file directory is generated. It is essential to specify both the XFDF path and the temporary file path during annotation export.
This example shows how to export annotations:
CPDFDocument document = readerView.getPDFDocument();
//the path of xfdf
String xfdfPath = context.getCacheDir().getAbsolutePath() + "/xfdf/exportXFDF.xfdf";
//the transfer path of audio and video files
String tmpxfdfPath = context.getCacheDir().getAbsolutePath() + "/tmp";
document.exportAnnotations(xfdfPath,tmpxfdfPath);
val document = readerView.pdfDocument
// the path of xfdf
val xfdfPath = "${context.cacheDir.absolutePath}/xfdf/exportXFDF.xfdf"
// the transfer path of audio and video files
val tmpxfdfPath = "${context.cacheDir.absolutePath}/tmp"
// Please ensure that the xfdf file saving folder and cache folder exist
document.exportAnnotations(xfdfPath, tmpxfdfPath)
What is XFDF
XFDF (XML Forms Data Format) is an XML format used to describe and transmit PDF form data. It is commonly used in conjunction with PDF files to store and pass values, states, and operations of form fields.
An XFDF file contains data corresponding to a PDF form, including the names, values, options, and formats of form fields.
XFDF serves as a format for describing form data and does not encompass the PDF file itself. It is employed for storing and transmitting form data, facilitating interaction and sharing between different systems and applications.