public static void passwordprotectedpdfexample() {
    try {
      OutputStream file = new FileOutputStream(new File("PasswordProtected.pdf"));
      Document document = new Document();
      PdfWriter writer = PdfWriter.getInstance(document, file);

      writer.setEncryption(
          USER_PASSWORD.getBytes(),
          OWNER_PASSWORD.getBytes(),
          PdfWriter.ALLOW_PRINTING,
          PdfWriter.ENCRYPTION_AES_128);

      document.open();
      document.add(new Paragraph("Password Protected pdf example !!"));
      document.close();
      file.close();

    } catch (DocumentException | IOException e) {

    }
  }