I have found that using java class we can protect pdf file with password
private static String USER_PASS = "Hello123";
private static String OWNER_PASS = "Owner123";
public static void main(String[] args) {
try {
OutputStream file = new FileOutputStream(new File("D:\\Test.pdf"));
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, file);
writer.setEncryption(USER_PASS.getBytes(), OWNER_PASS.getBytes(),
PdfWriter.ALLOW_PRINTING, PdfWriter.ENCRYPTION_AES_128);
document.open();
document.add(new Paragraph("Hello World, iText"));
document.add(new Paragraph(new Date().toString()));
document.close();
file.close();
} catch (Exception e) {
e.printStackTrace();
}
}
But how we can protect pdf file using javascript. I had referred the community question using javascript to password protect pdf but I am not able to solve my problem. Is there any source code so it can help me more. Please help.