pdf-file id=f📕
The or or Every All work both on the PDF file and its annotation format.
pdf-file element loads a PDF file into the document.
The pdf-page element embeds a page of a pdf-file.
Examples
Load from URL
<pdf-file id=f src=//pdf.ist/form.pdf></pdf-file>
<pdf-page of=f></pdf-page><pdf-file id=f></pdf-file>try { await f.load('//pdf.ist/form.pdf'); }
catch (e /* : PDFLoadError */) { /*E*/ } /*S*/f.addEventListener('error', e => { /*E*/ }, { once: true });
f.addEventListener('load', e => { /*S*/ }, { once: true });
f.src = '//pdf.ist/form.pdf';Save to System
await f .save(); // below export options
await f.XFDF.save(); // would apply here tooExport as Type
await f .export(); // : File
await f .export({ name: 'a.pdf' }); // = File{name: 'a.pdf', …}
await f .export(File); // : File
await f .export(Blob); // : Blob
await f .export({ type: Blob, noEdit: true }); // : Blob (without edits after load)
await f.XFDF.export(); // : XMLDocument
await f.XFDF.export({ indent: false }); // : XMLDocument
await f.XFDF.export(XMLDocument); // : XMLDocument (also supports: File | Blob)
await f.XFDF.export(String); // : String (via XMLDocument.toString())
await f.XFDF.export({ type: String, indent: false }); // : StringLoad from System
await f .open();
await f.XFDF.open();Load from Raw Data
const pdfData = await fetch('//pdf.ist/form.pdf' ).then(f => f.arrayBuffer());
const xfdfData = await fetch('//pdf.ist/form.xfdf').then(f => f.text());
await f .load( pdfData);
await f.XFDF.load(xfdfData);Load from File or ⋯FileHandles
await f .load(pdf /* : File */); // Distinguished by
await f.XFDF.load( xfdf /* : File */); // File.name extension.
await f .load(pdf, xfdf); // Load both at once.Load from System by Drag & Drop
pdf-page is a drop target for its file: drop a .pdf, an .xfdf, both, or a link on the page above.
<pdf-page of=f ></pdf-page> <!-- drop here -->
<pdf-page of=f -=drop></pdf-page> <!-- not here --><pdf-file id=s src=signed.pdf trust:src=roots.pem signatures></pdf-file>
<pdf-page of=s></pdf-page>const rows = await s.verify(); // [{ name, status, code, signerName, time, revocation, … }]Properties
<pdf-file id=f src=⋯ password=⋯ ium max:image-size=⋯ -=⋯></pdf-file> f.src
new Attribute Property Type Description Get Set
src src String The file URL (abs./rel.). + +
URL URL The file URL (abs.). + +
name String The file name. + +
data Uint8Array The file bytes at load. +
password password String The file password. + +
pages The linked pages: nested and of= pages. +
XFDF Object XML Forms Data Format. +
proxy Map Built-in CDN/CORS proxy. +
ium ium falsetrue Use high-fidelity rendering (PDFium). + +
max:image-size max.imageSize -1Number Images above width × height pixels are not drawn. + +
- off DOMTokenList 'text' 'anno' 'drop' 'controls' Turn layers, drag & drop or all controls off on its pages. +
controls controls falsetrue Viewer controls on its pages (multi-homed). + +
formData Object The form field values, by annotation ID. + +
js PDFDocumentProxy The PDF.js document. +
ready Boolean Connected with a src or data to load. +
event:prefix event.prefix null'type' Emit events as pdf-file-load, … + +
placeholder:aspect-ratio placeholder.aspectRatio '''A4' '16/9' '-' The placeholder of its pages while the PDF is on the way. + +
Properties (XFDF)
<pdf-file id=f xfdf:src=⋯></pdf-file> f.XFDF.src
new Attribute Property Type Description Get Set
xfdf:src src String The XFDF file URL (abs./rel.). + +
URL URL The XFDF file URL (abs.). + +
name String The XFDF file name. + +
Properties (Signatures)
<pdf-file id=s src=⋯ signatures trust:stores=⋯ trust:src=⋯ trust:srcdoc=⋯></pdf-file> s.trust.stores.add('eutl'); // + the EU trusted lists
s.trust.stores.add('-moz'); // - the <script>'s Mozilla roots
new Attribute Property Type Description Get Set
signatures signatures falsetrue Show signature cards on every page. + +
signed 'pending' 'verified' 'invalid' The worst signature status (read-only). +
trust:stores trust.stores DOMTokenList 'aatl' 'eutl' 'ms' 'moz' Trust anchors, from well-known root stores by name. +
trust:src trust.src String Trust anchors, from one URL. + +
trust:srcdoc trust.srcdoc String Trust anchors, inline. + +
Store Roots
'aatl' the Adobe Approved Trust List (Acrobat)
'eutl' the EU trusted lists: qualified CAs, status granted
'ms' Microsoft roots trusted for Document Signing (CCADB)
'moz' Mozilla roots trusted for email (CCADB)
Methods (IO)
await f. open(); // 📕 PDF file
await f.XFDF.open(); // ✏️ annotation
new async Method Arguments Return FS Picker FS Read FS Write FS Handle
🔄 open () File ± ± ±
🔄 load ( data? ) data? ± ±
🔄 save ( opts? ) File ± ± ±
🔄 saveAs ( opts? ) File ± ± ±
🔄 saveCopy( opts? ) File ± ±
close () ±
🔄 download( opts? ) +
🔄 saveData ( opts? ) Uint8Array String
🔄 export ( opts? ) type
Methods (Signatures)
const rows = await s.verify(); // cached: runs again when trust:* changes
const rows = await s.verify({ force: true }); // or when forced
new async Method Arguments Return
🔄 verify ( { force = )
Field Type Meaning
name String the signature field's full name
fieldName String the field's own name ( /T); '' without one
id String an opaque id: the field and the bytes it signs
kind 'signature' 'document-timestamp' a signature, or an RFC 3161 document timestamp
page Number null the page of its first widget
widgets Array the field's widgets; empty when the field cannot be found
String the widget's annotation id
Number null its page
[x1, y1, x2, y2] null its rectangle, in PDF points
Boolean shown: more than 1 pt wide and high, not hidden
status 'verified' 'unknown' 'untrusted' 'expired' 'revoked' 'invalid' the verdict; see the codes below
code String null why, e.g. 'EXPIRED'; null when verified
errorCode String null the same reason as Firefox names it, e.g. 'SEC_ERROR_EXPIRED_CERTIFICATE'
message String null the reason, in English
warnings Array what is worth knowing but does not change the verdict
String e.g. 'MODIFIED', 'REVOCATION_UNKNOWN', 'TRUST_SOURCE_FAILED', 'WEAK_SHA1'
String the warning, in English
signerName String null the signer as the PDF names it ( /Name), unverified; the verified name is certificate.subjectCN
reason String null why the signer says they signed ( /Reason)
location String null where the signer says they signed ( /Location)
contactInfo String null how to reach the signer, in their words ( /ContactInfo)
signingTime String null the claimed signing time as written ( /M), e.g. "D:20250101120000+01'00'"
signedAt Date null the same time as a Date
filter String null the signature handler ( /Filter), e.g. 'Adobe.PPKLite'
subFilter String null the format ( /SubFilter): 'adbe.pkcs7.detached' 'adbe.pkcs7.sha1' 'ETSI.CAdES.detached' 'ETSI.RFC3161'
signatureType 0 1 null PDF.js's number for the format: 0 adbe.pkcs7.detached, 1 adbe.pkcs7.sha1
byteRange [start, length, start, length] the bytes it signs ( /ByteRange)
revisionIndex Number its rank, the newest 0
parentId String null the id of the next newer signature
coversWholeDocument Boolean nothing but whitespace follows the bytes it signs
documentModifiedAfterSigning Boolean the document changed after it was signed: !coversWholeDocument
modificationsAfterSignature Number null updates saved after it
laterSignatures Number signatures and document timestamps added after it
laterTimestamps Number the document timestamps among them
onlyLaterSignatures Boolean every later update added a signature (counted, not inspected)
time Object null the time the certificates are checked at; null when the bytes do not check out
String that time
'timestamp' 'signingTime' 'M' 'now' where it comes from: a trusted timestamp, the signer's clock, the PDF date, or now
Boolean vouched for by a trusted time-stamp authority
Object the times the signer claims
String null the signer's clock (the CMS signing-time attribute)
String null the PDF date ( /M)
timestamp Object null its RFC 3161 timestamp; null without one
'trusted' 'untrusted' 'invalid' 'unknown' trusted: from a trusted authority, valid then · untrusted: valid, the authority not trusted · invalid: unreadable or not matching · unknown: an unsupported hash
String null when the authority stamped it
Number null its stated accuracy, in ms ( 0 when not stated)
String null the authority's policy OID
String null the token's serial number, in colon hex
String null the hash it stamps, e.g. 'SHA-256'
String null the authority's common name
Object null the authority's certificate, like certificate (no chain)
String null why it is not trusted
String null the same, in English
integrity Object the checks of the signed bytes and the signature
'ok' 'unknown' 'ok' once both check out; failures show in status
String null e.g. 'SHA-256'
String null e.g. 'rsaEncryption', 'ecdsa-with-SHA256'
Boolean null it signs CMS attributes too (time, certificate)
Object null the check of byteRange
Number bytes between the two signed ranges
Number bytes of the signature
true null the gap holds the signature and nothing else
certificate Object null the signer's certificate (the time-stamp authority's for a document timestamp)
String its subject, e.g. 'CN=⋯, O=⋯, C=⋯'
String its issuer, the same way
String the subject's common name (else its organization, else its unit)
String the issuer's common name
String null the subject's email address
String null the subject's organization
String valid from
String valid until
String in colon hex
String the SHA-256 of the certificate, in colon hex
String the certificate itself: DER, in base64
String e.g. 'RSA 3072', 'EC P-384', 'Ed25519'
String how its issuer signed it, e.g. 'sha256WithRSAEncryption'
[String] e.g. 'digitalSignature', 'nonRepudiation'
[String] e.g. 'documentSigning', 'timeStamping'
Boolean a certificate authority
Boolean issued to itself: the same subject and issuer
[String] its policy OIDs
Object null its EU qualified statements
Boolean an EU qualified certificate
Boolean its key is on a qualified signature creation device
Array the path to a trust anchor (when untrusted, the longest path found); each one has the fields of certificate but chain, and:
'signer' 'tsa' 'intermediate' 'anchor' its place in the path
Boolean valid at time.value
Object null its revocation check: the same object as in revocation.checked
trust Object the path to a trust anchor
'trusted' 'untrusted' 'unsupported' whether the path reaches a trust anchor
Object null the anchor reached, like certificate
String null why it is not trusted
validity Object the validity periods along the path
'ok' 'expired' 'notYetValid' null null when not checked
String null the time checked: time.value
Object null the first certificate not valid then, like certificate
revocation Object the revocation checks
'good' 'revoked' 'unknown' 'skipped' 'skipped' when the path is not trusted
Array one check per certificate of the path but the anchor
String the certificate checked
String its common name
'good' 'revoked' 'unknown' 'not-checked' 'not-checked': an OCSP responder that needs no check
'embedded-ocsp' 'embedded-crl' 'ocsp' 'crl' null where the answer came from
String null the URL asked online
String null when the answer was issued
String null when the next one is due
String null when the OCSP responder signed it
String null when it was revoked
String null why, e.g. 'keyCompromise'
Boolean revoked only after a trusted signing time, so still good
elapsedMs Number how long the check took, in ms
Status Codes
'invalid' MALFORMED_SIGNATURE BYTE_RANGE_MISMATCH DIGEST_MISMATCH SIGNATURE_MISMATCH ESS_CERT_MISMATCH ALG_PROTECTION_MISMATCH ENVELOPED_CONTENT NO_SIGNER ALGORITHM_DISABLED
'revoked' REVOKED
'expired' EXPIRED NOT_YET_VALID EXPIRED_ISSUER NOT_YET_VALID_ISSUER
'untrusted' NO_ANCHORS UNKNOWN_ISSUER SELF_SIGNED UNTRUSTED_ISSUER BAD_CERT_SIGNATURE CA_INVALID KEY_USAGE PATH_LEN UNKNOWN_CRITICAL_EXTENSION NAME_CONSTRAINTS CERT_ALG_DISABLED ALG_MISMATCH_CERT INADEQUATE_CERT_TYPE WEAK_KEY
'unknown' WEBCRYPTO_UNAVAILABLE SUBFILTER_NOT_SUPPORTED UNSUPPORTED_ALGORITHM NOCERT INTERNAL_ERROR
'verified' null
Events
const h = e => console.warn(e.type, e.detail);
f. addEventListener('load', h);
f.removeEventListener('load', h);
new Event Detail Fired When Bubbles Cancelable Composed
load File has loaded. + - ±
error Error File has failed IO. + - ±
verify { signatures, status } Signatures have been checked. + - ±