Sample code for 30+ languages & platforms
Dart 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 Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

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

  final pdf = CkPdf();

  // Load a PDF.
  try {
    pdf.loadFile('c:/someDir/sample.pdf');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

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

  ljd.emitCompact = false;

  print(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

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