Skip to main content

Encryption

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

Properties​

PropertyTypeDefaultDescription
encryptionTypestring—Encryption algorithm: RC4_40, RC4_128, AES_128, or AES_256
userPasswordstring—Password required to open the document
ownerPasswordstring—Password required to change permissions or remove protection
permissionsobject—Granular permission flags (see below)
doNotEncryptMetadatabooleanfalseWhen true, document metadata remains unencrypted
encryptEmbeddedFilesOnlybooleanfalseWhen true, only embedded file attachments are encrypted

Encryption types​

TypeKey lengthNotes
RC4_4040-bitLegacy, weak — use only for backward compatibility
RC4_128128-bitLegacy, supported by older viewers
AES_128128-bitModern, widely supported
AES_256256-bitStrongest available, recommended for sensitive documents

Permissions​

The permissions object controls what a user who opens the document with the user password is allowed to do.

PropertyTypeDefaultDescription
printbooleanfalseAllow printing
modifybooleanfalseAllow modifying document content
copybooleanfalseAllow copying text and graphics
annotatebooleanfalseAllow adding annotations
fillFormbooleanfalseAllow filling form fields
extractbooleanfalseAllow text extraction for accessibility
assemblebooleanfalseAllow inserting, rotating, or deleting pages

Examples​

Basic password protection​

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

Read-only with print allowed​

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

Form-fillable only​

{
"document": {
"encryption": {
"encryptionType": "AES_128",
"userPassword": "",
"ownerPassword": "formsAdmin",
"permissions": {
"print": true,
"fillForm": true,
"modify": false,
"copy": false,
"annotate": false,
"extract": 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": "AES_256",
"userPassword": "secure",
"ownerPassword": "admin",
"doNotEncryptMetadata": true
},
"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.