On this page
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:
- Open the document using the
CPDFReaderWidget
component. - Unlock the document and gain full permissions.
- 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 State | Description | Enum Value |
---|---|---|
None | No permissions are applied to the document | CPDFDocumentPermissions.none |
User | Document opened with user password; may have printing and copying restrictions | CPDFDocumentPermissions.user |
Owner | Document opened with owner password; no restrictions | CPDFDocumentPermissions.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');