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:
- Open the document using the
CPDFReaderView
component. - Unlock the document and gain full privileges.
- 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 Status | Description | Enum Value |
---|---|---|
No Permissions | No permissions applied to the document | CPDFDocumentPermissions.NONE |
User Permissions | Document opened with user password, some operations may be restricted | CPDFDocumentPermissions.USER |
Owner Permissions | Document opened with owner password, no restrictions | CPDFDocumentPermissions.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')