Skip to content

Removing Password

Removing the password refers to the process where a user with owner permissions removes both the owner and user passwords, allowing the document to be opened without a password and defaulting to full access without restrictions.

Steps to remove a password:

  1. Open the document using the CPDFReaderWidget component.
  2. Unlock the document and gain full permissions.
  3. Remove the password from the unlocked document.

Here is an example of how to remove a password:

dart
late CPDFReaderWidgetController _controller;

@override
Widget build(BuildContext context) {
  return Scaffold(
    resizeToAvoidBottomInset: false,
    appBar: AppBar(),
    body: Column(children: [
      TextButton(onPressed: () async{

        bool removePasswordResult = await _controller.document.removePassword();

      }, child: const Text('Encrypt PDF')),
      Expanded(child: CPDFReaderWidget(
        document: widget.documentPath,
        configuration: CPDFConfiguration(),
        onCreated: (controller) {
          setState(() {
            _controller = controller;
          });
        },
      ))
    ],));
}

For easy customization of UI for setting and removing passwords in Flutter, the following APIs are available:

Check if Document is Encrypted:

dart
bool isEncrypted = await controller.isEncrypted();

Get Document Permissions Status:

dart
CPDFDocumentPermissions permissions = await controller.getPermissions();

Different Permission States:

Permission StateDescriptionEnum Value
NoneNo permissions are applied to the documentCPDFDocumentPermissions.none
UserDocument opened with user password; may have printing and copying restrictionsCPDFDocumentPermissions.user
OwnerDocument opened with owner password; no restrictionsCPDFDocumentPermissions.owner

Check Owner Permissions:

dart
// Check if the current document is unlocked with owner permissions
bool unlocked = await controller.checkOwnerUnlocked();

// Check if the owner password is correct
bool result = await controller.checkOwnerPassword('owner_password');