PDFFileElement: XFDF property

Works in all major browsers
Since July 2026

WebPDF works in Chrome and Edge 125, Firefox 153 and Safari 18, on desktop and mobile, and in every later version: the oldest versions its PDF.js build supports, which already have every platform feature WebPDF needs. Since July 2026, that is every major browser.

The XFDF read-only property of the PDFFileElement interface returns an object for loading and saving the form data of a <pdf-file> as XFDF (XML Forms Data Format), with the same methods the file has for the PDF itself.

Value

An object with these properties and methods. The methods behave like the file's own, but read and write XFDF files (application/vnd.adobe.xfdf, .xfdf).

src

A string that reflects the xfdf:src HTML attribute: the URL of an XFDF file to apply after the PDF loads, and after every reload. A failed fetch is retried once through the built-in proxy.

URL

src resolved against the document's base URL, as a URL object.

name

The file name the methods save under: the last part of src, the name you set, the name of the file you opened, or the PDF's name with .xfdf.

open()

Shows a file picker for .xfdf files and applies the one you pick. See PDFFileElement.open().

load(data)

Applies form data: an XFDF string, a Blob, a File, a FileSystemFileHandle (which is then remembered) or an XMLDocument. A URL sets src. Without an argument, it reads the remembered .xfdf file again, or else fetches src again. It takes one argument only; to load a PDF and its XFDF together, use load(pdf, xfdf) on the file.

save(options)

Saves the form data, like PDFFileElement.save(). The options are name, declare (an XML declaration, true), indent (pretty print, true), href (the <f href> of the file, by default its name) and src (true: use the file's URL as href).

saveAs(options)

Saves the form data under a new name, like PDFFileElement.saveAs().

saveCopy(options)

Saves a copy of the form data, like PDFFileElement.saveCopy().

close()

Forgets the remembered .xfdf file and returns an Array of its handle: empty without the File System Access API.

saveData(options)

Resolves to the XFDF as a string.

export(options)

Resolves to the form data as an XMLDocument (the default), a String, a Blob or a File; pass the type as options.type or as the only argument.

XFDF stores one <field name> with a <value> per filled field. Radio groups store the chosen button's value, checkboxes their export value (or nothing when unchecked), multi-select lists one <value> per option. Loading matches fields by name.

Examples

Saving and loading form data

js
const file = document.querySelector("pdf-file");
await file.XFDF.save();                         // a .xfdf file of the filled fields
const xml = await file.XFDF.export(String);      // the same, as a string
await file.XFDF.load(xml);                       // applies it again

Filling a form from a file

html
<pdf-file id=f src=//new.webpdf.pro/forms.pdf xfdf:src=answers.xfdf></pdf-file>
<pdf-page of=f></pdf-page>

Specifications

Not part of any specification. <pdf-file> and <pdf-page> are autonomous custom elements defined by WebPDF.pro. It implements:

Specification
ISO 19444-1:2019 (XFDF)
ISO 32000-2:2020 (PDF 2.0)
# 12.7 Forms

Browser compatibility

desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
XFDF
1251251531111812515383182712518
  • XFDF · Firefox, Safari, Chrome Android, Firefox for Android, Opera Android, Safari on iOS, Samsung Internet, WebView Android, WebView on iOS: Without the File System Access API (Chrome Android 132, Opera Android 87, Samsung Internet 29 and WebView Android 132 have it), opening falls back to <input type=file> and saving to a download.

Legend

Full support
See implementation notes.

See also