PDFFileElement: load() method

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 load() method of the PDFFileElement interface loads a PDF into a <pdf-file>: from a URL, bytes, a Blob or a file, optionally with its XFDF form data.

Syntax

js
load()
load(data)
load(pdf, xfdf)

Parameters

data Optional

The PDF: a URL (as a string or a URL), a Blob, an ArrayBuffer, a Uint8Array, a File or a FileSystemFileHandle. Files and handles named .xfdf are loaded as form data instead. Without it, the file loads its current source again, or reads its remembered file handle again.

pdf, xfdf

Two File objects or handles, one named .pdf and one .xfdf, in either order: the PDF and its form data.

Return value

A Promise: for a URL or bytes, it resolves to data when the file has loaded; for a file or handle, to the File. With two arguments, it resolves to the PDF's File once the PDF has loaded and its form data is applied.

Exceptions

PDFLoadError

Rejects with this error (exported by the WebPDF module) when loading fails; its cause is the error event's error.

TypeError

Thrown for more than two arguments, or for two files that are not one .pdf and one .xfdf.

Usage notes

Examples

Loading a file and waiting for it

js
const file = document.querySelector("pdf-file");
try {
  await file.load("//new.webpdf.pro/forms.pdf");
} catch (error) {
  console.warn(error.message, error.cause); // "data failed to load", and why
}

Loading a PDF with its form data

js
const [pdf, xfdf] = input.files; // form.pdf and form.xfdf
await document.querySelector("pdf-file").load(pdf, xfdf);

Specifications

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

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
load()
1251251531111812515383182712518

Legend

Full support

See also