Skip to content
Guides

Remove Password

Removing the password means the user with owner privileges removes the user password and owner password, allowing the document to be opened without a password and granting full access by default.

The steps to remove a password:

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

The following example demonstrates how to remove a password:

tsx
const CPDFReaderViewExampleScreen = () => {

  const pdfReaderRef = useRef<CPDFReaderView>(null);

  const [samplePDF] = useState(
    (Platform.OS === 'android'
     ? 'file:///android_asset/PDF_Document.pdf'
     : 'PDF_Document.pdf')
  );

  return (
    <View style={{ flex: 1 }}>
      <Button title='Remove Password' onPress={async () => {

          var document = pdfReaderRef.current?._pdfDocument;
          const removeResult = await document?.removePassword();

        }}></Button>
      <CPDFReaderView
        ref={pdfReaderRef}
        document={samplePDF}
        configuration={ComPDFKit.getDefaultConfig({
          toolbarConfig: {
            mainToolbarVisible: true,
            iosLeftBarAvailableActions: [
              CPDFToolbarAction.THUMBNAIL
            ]
          }
        })}
        />
    </View>
  );
};

Check if the Document is Encrypted:

tsx
var document = pdfReaderRef.current?._pdfDocument;
const isEncrypted = await document?.isEncrypted()

Get Document Permission Status:

dart
var document = pdfReaderRef.current?._pdfDocument;
const permissions = await document?.getPermissions();

Permission Status Explanation:

Permission StatusDescriptionEnum Value
No PermissionsNo permissions applied to the documentCPDFDocumentPermissions.NONE
User PermissionsDocument opened with user password, some operations may be restrictedCPDFDocumentPermissions.USER
Owner PermissionsDocument opened with owner password, no restrictionsCPDFDocumentPermissions.OWNER

Check Owner Permissions:

tsx
var document = pdfReaderRef.current?._pdfDocument;
// Check if the document is unlocked with owner privileges
const unlocked = await document?.checkOwnerUnlocked()

// Check if the owner password is correct
const result = await document?.checkOwnerPassword('4321')