Password Protection of PDF Files

2019-04-14 12:56发布

We have a requirement to protect PDF files using a password. Are there any Java-based, open source tools which will help us in this regard?

4条回答
疯言疯语
2楼-- · 2019-04-14 13:01
兄弟一词,经得起流年.
3楼-- · 2019-04-14 13:03

I would recommend using the iText java PDF library.

Inside iText, there is a class called PdfEncrypter which should let you password protect a PDF file.

查看更多
\"骚年 ilove
4楼-- · 2019-04-14 13:14

You can easily make the Password protected pdf file in java......to do so you will require two addtional jar/lib bctsp-jdk16-1.46.jar and bcprov-jdk16-1.46.jar along with the itextpdf-5.2.1.jar.
Download all jars from here Download Jars

Also below is the snippet of the code

private static String USER_PASSWORD = "password";
private static String OWNER_PASSWORD = "naveen";
public static void main(String[] args) throws IOException {

    Document document = new Document();
      try
      {

         PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("E:\\HelloWorld.pdf"));
         writer.setEncryption(USER_PASSWORD.getBytes(),OWNER_PASSWORD.getBytes(), PdfWriter.ALLOW_PRINTING,PdfWriter.ENCRYPTION_AES_128);
         document.open();
         document.add(new Paragraph("This is Password Protected PDF document."));
         document.close();
         writer.close();
      } catch (DocumentException e)
      {
         e.printStackTrace();
      } catch (FileNotFoundException e)
      {
         e.printStackTrace();
      }
}
查看更多
孤傲高冷的网名
5楼-- · 2019-04-14 13:25
登录 后发表回答