DEV Community 👩‍💻👨‍💻

DEV Community 👩‍💻👨‍💻 is a community of 966,904 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
CodeSharing
CodeSharing

Posted on

Java/ Protect Presentation Slides

To protect a PowerPoint document from being snooped or modified, Free Spire.Presentation for Java enables developers to encrypt the PowerPoint files with password or to set write protection to make the presentation read only. In this article, you will learn how to use the above two methods to protect the presentation slides.

Import jar dependency

● You can download the free library and unzip it, and then add the Spire.Presentation.jar file to your project as dependency.

● Or you can directly add the jar dependency to your maven project by adding the following configurations to the pom.xml.

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.presentation.free</artifactId>
        <version>3.9.0</version>
    </dependency>
</dependencies>
Enter fullscreen mode Exit fullscreen mode

Encrypt PowerPoint File

Free Spire.Presentation for Java offers the Presentation.encrypt() method to encrypt the whole document with specified password.

import com.spire.presentation.*;

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

        //Load a PPT document
        Presentation presentation = new Presentation();
        presentation.loadFromFile("Sample.pptx");


        //Encrypt the document with the password
        presentation.encrypt("abc-123");

        //Save the file
        presentation.saveToFile("output/Encrypted.pptx", FileFormat.PPTX_2010);
    }
}
Enter fullscreen mode Exit fullscreen mode

Encrypt

Set the Presentation Slides Read Only

The Presentation.protect() method allows developers to protect the PowerPoint document with password. Unlike the Presentation.encrypt() method mentioned above, the users only need to enter the password when they want to modify the document, otherwise they can directly open the document in read-only mode.

import com.spire.presentation.*;

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

        //Load a PowerPoint document.
        Presentation presentation = new Presentation();
        presentation.loadFromFile("Sample.pptx");

        //Protect the document with the password
        presentation.protect("123456");

        //save the file
        presentation.saveToFile("output/Readonly.pptx", FileFormat.PPTX_2010);
    }
}
Enter fullscreen mode Exit fullscreen mode

Read only

Top comments (0)

🌚 Life is too short to browse without dark mode