Skip to content

删除密码

删除密码是指拥有所有者权限的用户移除用户密码和所有者密码,使文档无需密码即可打开,并默认拥有完全访问权限。

删除密码的步骤:

  1. 使用 CPDFReaderWidget 组件打开文档。
  2. 解锁文档并获取完全权限。
  3. 从解锁的文档中移除密码。

以下示例展示了如何删除密码:

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('删除密码')),
      Expanded(child: CPDFReaderWidget(
        document: widget.documentPath,
        configuration: CPDFConfiguration(),
        onCreated: (controller) {
          setState(() {
            _controller = controller;
          });
        },
      ))
    ],));
}

检查文档是否已加密:

dart
bool isEncrypted = await controller.isEncrypted();

获取文档权限状态:

dart
CPDFDocumentPermissions permissions = await controller.getPermissions();

权限状态说明:

权限状态描述枚举值
无权限文档未应用任何权限CPDFDocumentPermissions.none
用户权限使用用户密码打开文档,可能限制打印和复制等操作CPDFDocumentPermissions.user
所有者权限使用所有者密码打开文档,无任何限制CPDFDocumentPermissions.owner

检查所有者权限:

dart
// 检查当前文档是否通过所有者权限解锁
bool unlocked = await controller.checkOwnerUnlocked();

// 检查所有者密码是否正确
bool result = await controller.checkOwnerPassword('owner_password');