Skip to main content

Encryption

The encryption object adds password protection to the generated PDF and DOCX. You can set separate user and owner passwords and control what actions readers are allowed to perform.

Encrypted PDFs are not archival

PDF/A forbids encryption. An encrypted PDF is delivered without its PDF/A claim, and the render notes it. A definition that claims a PDF/A part and also sets encryption is refused: choose one. To keep a document both archival and confidential, leave the PDF unencrypted and protect it where it is stored and sent. See Conformance.

Properties​

PropertyTypeDefaultDescription
encryptionTypestring"aes256"The cipher: aes256, aes256Gcm or aes128 (see below)
userPasswordstring—The password that opens the document. Absent, it opens without one and the permissions still hold
ownerPasswordstring—The password that lifts the permissions. Absent, a random one is drawn, so nobody holds it
permissionsobject—What a reader may do without the owner password (see below)
encryptMetadatabooleantrueWhether the document's metadata is encrypted with it; false leaves it readable to a search tool
encryptEmbeddedFilesOnlybooleanfalseEncrypts only the attached files, leaving the document itself readable

Encryption types​

TypeNotes
aes256AES-256, the default and the recommended cipher
aes256GcmAES-256 in GCM mode, defined over PDF 2.0: an unpinned document becomes PDF 2.0, and under a 1.7 pin AES-256 is written instead, with a warning
aes128AES-128, deprecated by PDF 2.0: a 2.0 document gets AES-256 instead, with a warning

RC4 is not offered: it is broken, and PDF 2.0 deprecates it.

Permissions​

The permissions object controls what a user who opens the document with the user password is allowed to do. Absent, printing at full quality is allowed and nothing else; {} grants nothing.

PropertyTypeDefaultDescription
printbooleanfalseAllow printing
printHighQualitybooleantrueAllow printing at full quality; false allows degraded printing only, so set print too
modifybooleanfalseAllow modifying document content
copybooleanfalseAllow copying text and graphics
annotatebooleanfalseAllow adding comments and filling forms
fillFormbooleanfalseAllow filling form fields
assemblebooleanfalseAllow inserting, rotating, or deleting pages

In a DOCX​

A DOCX is protected from the same encryption object, as far as Word's format allows:

KeyIn the DOCX
userPasswordThe file is encrypted and opens under this password, with AES-256. Without one, the DOCX is not encrypted and opens without a password
ownerPassword and permissionsBecome Word's editing restriction, locked under the owner password: read-only, comments only, or filling in forms, by the permissions granted. Allowing modify leaves editing unrestricted
encryptionTypeA DOCX is always encrypted with AES-256
permissions.print, copy, assemble, printHighQualityNo equivalent in a DOCX. A denied one is reported, and not applied
encryptMetadata, encryptEmbeddedFilesOnlyNo equivalent: the whole file is encrypted
note

Word's editing restriction keeps honest readers from editing, but the Office Open XML standard says it is not a security feature. Only userPassword makes the content unreadable without the password.

Examples​

Basic password protection​

{
"document": {
"encryption": {
"encryptionType": "aes256",
"userPassword": "viewerPass123",
"ownerPassword": "adminPass456"
},
"content": [
{ "p": "This document requires a password to open." }
]
}
}

Read-only with print allowed​

{
"document": {
"encryption": {
"encryptionType": "aes256",
"userPassword": "readonly",
"ownerPassword": "owner",
"permissions": {
"print": true,
"copy": false,
"modify": false,
"annotate": false,
"fillForm": false,
"assemble": false
}
},
"content": [
{ "p": "This document can be viewed and printed, but not edited or copied." }
]
}
}

Form-fillable only​

{
"document": {
"encryption": {
"encryptionType": "aes128",
"userPassword": "",
"ownerPassword": "formsAdmin",
"permissions": {
"print": true,
"fillForm": true,
"modify": false,
"copy": false,
"annotate": false,
"assemble": false
}
},
"content": [
{ "p": "Fill in the fields below:" }
]
}
}

An empty userPassword allows opening without a password while still enforcing permission restrictions.

Unencrypted metadata​

{
"document": {
"metadata": {
"title": "Confidential Report",
"author": "Operations Team"
},
"encryption": {
"encryptionType": "aes256",
"userPassword": "secure",
"ownerPassword": "admin",
"encryptMetadata": false
},
"content": [
{ "p": "Metadata is searchable even though the document is encrypted." }
]
}
}

This is useful when documents need to be indexed by a document management system without requiring the password.