Sample code for 30+ languages & platforms
React Native Requires Chilkat v11.0.0+

PDF Get Encryption and Permissions Information

See more PDF Signatures Examples

Determine if a PDF is encrypted, and the associated user permissions.

Note: Some PDFs are encrypted but not password-protected. In such cases, encryption is used primarily for preventing unauthorized modifications to the document, but it doesn't restrict access. Therefore, you can open and read the document without a password.

Chilkat React Native Downloads

React Native
import { JsonObject, Pdf } from '@chilkat/react-native'

function chilkatExample() {
  // This example requires the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  const pdf = new Pdf();

  // Load a PDF.
  try {
    pdf.loadFile('c:/someDir/sample.pdf');
  } catch {
    console.log(pdf.lastErrorText);
    return;
  }

  // Get information about the PDF that was collected in the call to LoadFile.
  const ljd = new JsonObject();
  pdf.getLastJsonData(ljd);

  ljd.emitCompact = false;

  console.log(ljd.emit());

  // Sample output:

  // {
  //   "pdfVersion": "1.6",
  //   "encrypt": {
  //     "filter": "/Standard",
  //     "keyLength": 128,
  //     "V": 4,
  //     "R": 4,
  //     "P": -1340,
  //     "perm": {
  //       "printLowResolution": "allowed",
  //       "printHighResolution": "allowed",
  //       "modifyOther": "not allowed",
  //       "modifyAnnotations": "allowed",
  //       "modifyForms": "not allowed",
  //       "fillInForms": "allowed",
  //       "assembleDoc": "allowed",
  //       "extractAnyPurpose": "not allowed",
  //       "extractAccessibility": "not allowed"
  //     },
  //     "method": "AESV2"
  //   }
  // }

  // Use this online tool to generate parsing code from sample JSON: 
  // Generate Parsing Code from JSON

  const pdfVersion = ljd.stringOf('pdfVersion');
  const filter = ljd.stringOf('encrypt.filter');
  const keyLength = ljd.intOf('encrypt.keyLength');
  const v = ljd.intOf('encrypt.V');
  const r = ljd.intOf('encrypt.R');
  const p = ljd.intOf('encrypt.P');
  const printLowResolution = ljd.stringOf('encrypt.perm.printLowResolution');
  const printHighResolution = ljd.stringOf('encrypt.perm.printHighResolution');
  const modifyOther = ljd.stringOf('encrypt.perm.modifyOther');
  const modifyAnnotations = ljd.stringOf('encrypt.perm.modifyAnnotations');
  const modifyForms = ljd.stringOf('encrypt.perm.modifyForms');
  const fillInForms = ljd.stringOf('encrypt.perm.fillInForms');
  const assembleDoc = ljd.stringOf('encrypt.perm.assembleDoc');
  const extractAnyPurpose = ljd.stringOf('encrypt.perm.extractAnyPurpose');
  const extractAccessibility = ljd.stringOf('encrypt.perm.extractAccessibility');
  const method = ljd.stringOf('encrypt.method');
}