Protect a Presentation from Editing
The DevExpress Presentation API protects PowerPoint presentations from editing with a password. A protected presentation opens in read-only mode. Users must enter the correct password to edit the presentation.
Protect a Presentation from Editing
Follow these steps to enable write protection:
- Create a WriteProtectionOptions object and specify a password and hash algorithm.
- Pass the
WriteProtectionOptionsobject to the Presentation.protect() method.
The following code snippet applies password-based write protection:
package presentation;
import com.devexpress.docs.office.*;
import com.devexpress.docs.presentation.*;
import java.io.*;
import java.nio.file.*;
public class Main {
public static void main(String[] args) throws Exception {
try(Presentation presentation =
new Presentation(
Files.readAllBytes(
Path.of("Presentation.pptx")))) {
// Enable write protection.
WriteProtectionOptions options =
new WriteProtectionOptions("password", HashAlgorithmType.SHA512);
presentation.protect(options);
Path outputDir = Path.of("output");
Files.createDirectories(outputDir);
// Save the protected presentation.
try (FileOutputStream fileStream = new FileOutputStream(
outputDir.resolve("ProtectedPresentation.pptx").toFile())) {
presentation.saveDocument(fileStream);
}
}
}
}
Remove Write Protection
Call the Presentation.removeProtection() method to remove write protection from a presentation:
presentation.removeProtection();
Save the presentation after you remove protection.
See Also