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.
This sample shows how to set permission passwords for opening documents and decrypt them.
// Import the JS file of ComPDFKit Web Demo.
import ComPDFKitViewer from "@compdfkit_pdf_sdk/webviewer";
const viewer = document.getElementById('webviewer');
ComPDFKitViewer({
path: '/',
initialDoc: 'Your PDF Url',
licenseKey: 'Input your license here'
}, viewer)
.then((instance) => {
const { documentViewer } = instance.Core;
documentViewer.addEventListener('documentLoaded', async () => {
console.log('ComPDFKit Web Demo loaded');
const doc = documentViewer.getDocument();
// Sample1: Encrypt
try {
await doc.setPassword({ userPassword: 'password' });
console.log('File is encrypted.');
} catch (e) {
console.log('File encrypt failed');
}
// Sample2: Unlock
try {
await doc.setPassword({});
console.log('File is unlocked.');
} catch (e) {
console.log('File unlock failed');
}
})
})