Java 経由でPDFを暗号化

Java を使用して、Aspose.PDF ライブラリで PDF ファイルをロックします。

Java ライブラリを使用してPDFドキュメントを暗号化

PDFファイルを暗号化するために、Javaプラットフォーム用の機能が豊富で強力で使いやすい変換APIである [Aspose.PDF for Java](https://products.aspose.com/pdf/java)APIを使用します。最新バージョンを Maven から直接ダウンロードし、pom.xmlに以下の設定を追加することで、Mavenベースのプロジェクト内にインストールできます。

Repository

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java AP</name>
    <url>https://releases.aspose.com/java/repo/</url>
</repository>

Dependency

<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-pdf</artifactId>
<version>version of aspose-pdf API</version>
</dependency>

Java 経由でPDFを暗号化する方法


ご使用の環境でコードを試すには Aspose.PDF for Java が必要です。

1。Document オブジェクトを使用して PDF ドキュメントを開きます。 1。ユーザーと所有者のパスワードを作成します。 1。Document.Encrypt メソッドを呼び出します。 1。PDF ファイルを保存します。

<% encrypt.code-block.text %>

PDF ドキュメントを暗号化-Java。

<% encrypt.code-block.subtitle %>

Input file:

File not added

Password:

Output format:

Output file:


  Document document = new Document(_dataDir + "input.pdf");
  DocumentPrivilege documentPrivilege = DocumentPrivilege.getForbidAll();
  documentPrivilege.setAllowScreenReaders(true);
  document.encrypt("user", "owner", documentPrivilege, CryptoAlgorithm.AESx128, false);
  document.save(_dataDir + "SetPrivileges_out.pdf");