Skip to content

导入和导出表单

导入和导出 XFDF 表单的方法使用户能够保存和还原PDF文档表单数据,方便填写表单数据。

导入表单

在通过 XFDF 导入表单时,会产生临时文件目录,在导入表单要同时指定 xfdf 路径和临时文件路径。

导入表单的代码如下:

java
//the path of xfdf
String xfdfPath = context.getCacheDir().getAbsolutePath() + "/xfdf/exportXFDF.xfdf";

//the transfer path of audio and video files
File tempFilePath = new File(context.getCacheDir(), "tmp");
tempFilePath.mkDirs();

document.importWidgets(xfdfPath,tempFilePath.getAbsolutePath());
kotlin
// the path of xfdf
val xfdfPath: String =  "${context.cacheDir.absolutePath}/xfdf/exportXFDF.xfdf"
// the transfer path of audio and video files
val tempFilePath : File = File(context.cacheDir(), "tmp")
tempFilePath.mkDirs()
// Please make sure the 'tmpxfdfPath' folder exists
document.importWidgets(xfdfPath, tempFilePath.absolutePath)

导出表单

在通过 XFDF 导出表单时,会产生临时文件目录,在导出表单时需要同时指定 xfdf 路径和临时文件路径。

导出表单的代码如下:

java
CPDFDocument document = readerView.getPDFDocument();
//the path of xfdf
File xfdfFile = new File(context.getCacheDir(), "/xfdf/exportXFDF.xfdf");
xfdfFile.getParentFile().mkdirs();

//the transfer path of audio and video files
File tmpXfdfFile = new File(context.getCacheDir(), "/tmp");
tmpXfdfFile.mkdirs();

document.exportWidgets(xfdfFile.getAbsolutePath(),tmpXfdfFile.getAbsolutePath());
kotlin
val document = readerView.pdfDocument
// the path of xfdf
val xfdfFile = File(context.cacheDir, "/xfdf/exportXFDF.xfdf")
xfdfFile.parentFile?.mkdirs()

// the transfer path of audio and video files
val tmpXfdfFile = File(context.cacheDir, "/tmp")
tmpXfdfFile.mkdirs()

document.exportWidgets(xfdfFile.absolutePath, tmpXfdfFile.absolutePath)

什么是XFDF

XFDF(XML Forms Data Format)是一种用于描述和传输 PDF 表单数据的XML格式。它通常与 PDF 文件一起使用,用于存储和传递表单字段的值、状态和操作。

XFDF 文件包含了对应 PDF 表单的数据,其中包括表单字段的名称、值、选项、格式等。

XFDF 是一种用于描述表单数据的格式,并不包含 PDF 文件本身。它用于存储和传输表单数据,以便在不同系统和应用程序之间进行交互和共享。