Doko's new lair
React Native PDF Editor

Encryption

Password-protect PDFs and inspect encryption settings.

Check whether a file is encrypted

import { PdfDocument } from '@doko/react-native-pdf-editor';

const encrypted = await PdfDocument.isEncrypted('/path/to/file.pdf');

This checks a file path without you needing to keep a document open.

Open an encrypted PDF

const doc = await PdfDocument.open('/path/to/protected.pdf', 'user-password');

If the password is wrong, the native load call rejects.

Encrypt a document

const doc = await PdfDocument.open('/path/to/source.pdf');

doc.setEncrypted('user-password', 'owner-password');
await doc.save('/path/to/protected.pdf');

The current binding uses PoDoFo's default modern encryption for newly protected documents: AES-256, PDF 2.0 revision 6.

Permissions

Permissions are optional. Omitted flags default to true.

doc.setEncrypted('open-me', 'owner-secret', {
  print: true,
  copy: false,
  edit: false,
  editNotes: false,
  fillAndSign: true,
  accessible: true,
  docAssembly: false,
  highPrint: false,
});

Supported permission flags:

FlagMeaning
printAllow printing
editAllow general document modification
copyAllow text and graphic extraction
editNotesAllow annotations/form edits
fillAndSignAllow filling forms and signature fields
accessibleAllow accessibility extraction
docAssemblyAllow document assembly operations
highPrintAllow high-resolution printing

PDF permissions are advisory in the PDF security model. Viewers and processors decide how strictly to honor them.

Inspect encryption info

const info = doc.getEncryptionInfo();

if (info) {
  console.log(info.algorithm);
  console.log(info.keyLengthBits);
  console.log(info.revision);
  console.log(info.permissions.copy);
}

The shape is:

interface PdfEncryptionInfo {
  algorithm: string;
  keyLengthBits: number;
  revision: number;
  metadataEncrypted: boolean;
  parsed: boolean;
  ownerPasswordSet: boolean;
  permissions: PdfEncryptionPermissions;
}

getEncryptionInfo() returns undefined for unencrypted documents.

About older encrypted PDFs

PoDoFo may report older algorithms such as RC4 or AESv2 when inspecting an existing PDF. That is about the source file's security dictionary, not the algorithm used when you call setEncrypted() on a new output.

On this page