チュートリアル

簡単にライブラリーを使用するためのチュートリアルコレクション

チュートリアル»Java»Spire.Presentation for Java»保護»Java:PowerPoint プレゼンテーションを保護または保護解除する方法
2024-02-29

Java:PowerPoint プレゼンテーションを保護または保護解除する方法

場合によっては、PowerPoint ドキュメントを保護する必要があるかもしれません。 たとえば、権限のないユーザーが PowerPoint ドキュメントを表示および編集できないようにしたい場合です。 逆に、PowerPoint ドキュメントの保護を解除する必要がある場合もあります。 たとえば、パスワードで保護された PowerPoint ドキュメントを誰でもアクセスできるようにしたい場合です。この記事では、Spire.Presentation for Java を使用して PowerPoint プレゼンテーションを保護または保護解除する方法を示します。

Spire.Presentation for Java をインストールします

まず、Spire.Presentation for Javaを Java プロジェクトに追加する必要があります。JAR ファイルは、このリンクからダウンロードできます。Maven を使用する場合は、次のコードをプロジェクトの pom.xml ファイルに追加する必要があります。

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.presentation</artifactId>
        <version>9.2.2</version>
    </dependency>
</dependencies>

PowerPoint プレゼンテーションをパスワードで保護する

PowerPoint をパスワードで保護すると、正しいパスワードを持つユーザーだけがドキュメントを表示および編集できるようになります。 以下に詳細な手順を示します。

  • Presentation クラスのインスタンスを初期化します。
  • Presentation.loadFromFile() メソッドを使用して PowerPoint ドキュメントをロードします。
  • Presentation.encrypt() メソッドを使用して、ドキュメントをパスワードで暗号化します。
  • Presentation.saveToFile() メソッドを使用して結果ドキュメントを保存します。
  • Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;

public class ProtectPPTWithPassword {
    public static void main(String []args) throws Exception {

        //Presentationインスタンスを作成する
        Presentation presentation = new Presentation();

        //PowerPoint ドキュメントをロードする
        presentation.loadFromFile("Sample.pptx");

        //ドキュメントをパスワードで暗号化する
        presentation.encrypt("your password");

        //結果ドキュメントを保存する
        presentation.saveToFile("Encrypted.pptx", FileFormat.PPTX_2013);

    }
}

Java:PowerPoint プレゼンテーションを保護または保護解除する方法

PowerPoint プレゼンテーションを最終版としてマークする

PowerPoint ドキュメントを最終版としてマークすると、ドキュメントが最終バージョンであり、それ以上編集する必要がないことを読者に知らせることができます。以下に詳細な手順を示します。

  • Presentation クラスのインスタンスを初期化します。
  • Presentation.loadFromFile() メソッドを使用して PowerPoint ドキュメントをロードします。
  • Presentation.getDocumentProperty().set() メソッドを使用して、ドキュメントを最終版としてマークします。
  • Presentation.saveToFile() メソッドを使用して結果ドキュメントを保存します。
  • Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;

public class MarkPPTAsFinal {
    public static void main(String []args) throws Exception {

        //Presentationインスタンスを作成する
        Presentation ppt = new Presentation();

        //PowerPoint ドキュメントをロードする
        ppt.loadFromFile("Sample.pptx");

        //ドキュメントを最終版としてマークする
        ppt.getDocumentProperty().set("_MarkAsFinal", true);

        //結果ドキュメントを保存する
        ppt.saveToFile("MarkAsFinal.pptx", FileFormat.PPTX_2013);
    }
}

Java:PowerPoint プレゼンテーションを保護または保護解除する方法

PowerPoint プレゼンテーションからパスワード保護を削除する

文書の保護が不要になった場合は、パスワードを削除して保護を解除することもできます。以下に詳細な手順を示します。

  • Presentation クラスのインスタンスを初期化します。
  • Presentation.loadFromFile() メソッドを使用して PowerPoint ドキュメントをロードします。
  • Presentation.removeEncryption() メソッドを使用して、ドキュメントからパスワード保護を削除します。
  • Presentation.saveToFile() メソッドを使用して結果ドキュメントを保存します。
  • Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;

public class RemovePasswordProtectionFromPPT {
    public static void main(String []args) throws Exception {

        //Presentationインスタンスを作成する
        Presentation presentation = new Presentation();

        //パスワードで保護された PowerPoint ドキュメントをロードする
        presentation.loadFromFile("Encrypted.pptx", "your password");

        //ドキュメントからパスワード保護を削除する
        presentation.removeEncryption();

        //結果ドキュメントを保存する
        presentation.saveToFile("RemoveProtection.pptx", FileFormat.PPTX_2013);

    }
}

Java:PowerPoint プレゼンテーションを保護または保護解除する方法

PowerPoint プレゼンテーションから最終オプションとしてマークを削除する

「最終版にする」機能は、PowerPoint ドキュメントを読み取り専用にして、それ以上の変更を防止します。 ドキュメントを再度変更したい場合は、ドキュメントから「最終版にする」機能を削除できます。以下に詳細な手順を示します。

  • Presentation クラスのインスタンスを初期化します。
  • Presentation.loadFromFile() メソッドを使用して PowerPoint ドキュメントをロードします。
  • Presentation.getDocumentProperty().set() メソッドを使用して、ドキュメントから「最終版にする」機能を削除します。
  • Presentation.saveToFile() メソッドを使用して結果ドキュメントを保存します。
  • Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;

public class RemoveMarkAsFinalFromPPT {
    public static void main(String []args) throws Exception {

        //Presentationインスタンスを作成する
        Presentation ppt = new Presentation();

        //PowerPoint ドキュメントをロードする
        ppt.loadFromFile( "MarkAsFinal.pptx");

        //ドキュメントから「最終版にする」機能を削除する
        ppt.getDocumentProperty().set("_MarkAsFinal", false);

        //結果ドキュメントを保存する
        ppt.saveToFile("RemoveMarkAsFinal.pptx", FileFormat.PPTX_2013);
    }
}

Java:PowerPoint プレゼンテーションを保護または保護解除する方法

一時ライセンスを申請する

結果ドキュメントから評価メッセージを削除したい場合、または機能制限を取り除く場合は、についてこのメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。にお問い合わせ、30 日間有効な一時ライセンスを取得してください。

Read 74 times