PDF 文件的密码保护

发布于 2024-08-17 10:27:53 字数 53 浏览 4 评论 0原文

我们需要使用密码来保护 PDF 文件。有没有基于 Java 的开源工具可以在这方面帮助我们?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

听闻余生 2024-08-24 10:27:53

您可以轻松地在java中制作受密码保护的pdf文件……为此,您将需要两个附加的jar/lib bctsp-jdk16-1.46.jar和bcprov-jdk16-1.46.jar以及itextpdf-5.2。 1.jar.
从这里下载所有 jars 下载 Jars

下面也是代码片段

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();
      }
}

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();
      }
}
暗藏城府 2024-08-24 10:27:53

我建议使用 iText java PDF 库。

在 iText 内部,有一个名为 PdfEncrypter 的类,它应该让您用密码保护 PDF 文件。

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.

栖迟 2024-08-24 10:27:53

您可以使用 iText PDF for java 来完成此操作:

一些示例:

http://1t3xt.info/examples/browse/?page=example&id=42

you can do it with iText PDF for java:

some examples:

http://1t3xt.info/examples/browse/?page=example&id=42

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文