PDF Generation Template Editor
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
The PDF permission module ensures document security by providing encryption, document permissions, decryption, and password removal functions. It allows users to securely control and manage the document.
Encryption
Encryption consists of two parts: user password and owner password.
This dual-password system is designed to offer more flexible and secure document access and management.
ComPDF provides various encryption algorithms and permission settings. Based on your needs, you can choose the appropriate algorithm and configure custom permissions to protect the document.
The encryption steps are as follows:
The following example demonstrates how to encrypt a document:
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='Set Password' onPress={async () => {
var document = pdfReaderRef.current?._pdfDocument;
const allowsPrinting = false;
const allowsCopy = false;
const result = await document?.setPassword(
'1234', // Document opening password
'4321', // Owner password
allowsPrinting,
allowsCopy,
CPDFDocumentEncryptAlgo.AES128);
console.log('ComPDF-RN setPassword:', result);
}}></Button>
<CPDFReaderView
ref={pdfReaderRef}
document={samplePDF}
configuration={ComPDFKit.getDefaultConfig({
toolbarConfig: {
mainToolbarVisible: true,
iosLeftBarAvailableActions: [
CPDFToolbarAction.THUMBNAIL
]
}
})}
/>
</View>
);
};Different Encryption Algorithms
| Encryption Algorithm | Description | Enum Value |
|---|---|---|
| No Encrypt Algo | No encryption | CPDFDocumentEncryptAlgo.noEncryptAlgo |
| RC4 | Key-based XOR encryption of plaintext | CPDFDocumentEncryptAlgo.rc4 |
| AES-128 | AES encryption with a 128-bit key | CPDFDocumentEncryptAlgo.aes128 |
| AES-256 | AES encryption with a 256-bit key | CPDFDocumentEncryptAlgo.aes256 |