Skip to content

PDF 生成模板编辑器

开源可视化 PDF 生成引擎,支持自定义模板,并提供面向开发者的 API,灵活构建文档生成流程。

查看 GitHub

导入导出表单 ​

如果想要通过 XFDF 将表单导入或导出,可以通过 annotationManager 的 exportAnnotations 以及 importAnnotations 来实现

导入表单 ​

在文档加载完成后,可以通过 importAnnotations 导入 XFDF 中的域值(<fields>),每个值会填入文档中同名的域。XFDF 的类型可以为字符串或 File 类型

javascript
await annotationManager.importAnnotations(xfdf)

导出表单 ​

在文档加载完成后,可以通过 exportAnnotations 导出域值,得到 XFDF 字符串。annotationList 只传表单控件时,不会导出其它注释。表单控件本身保存在 PDF 中。

javascript
const { Annotations } = instance.Core
const widgets = annotationManager.getAnnotationsList().filter(annotation => annotation instanceof Annotations.WidgetAnnotation)
const xfdfString = await annotationManager.exportAnnotations({ annotationList: widgets, fields: true })