Java: Verify if a PowerPoint Document is Digitally Signed
PowerPoint documents signed with digital signatures can help recipients check if they have been altered since they were signed. If any changes are made, the signatures will become invalid immediately. Therefore, before you edit a PowerPoint document, you should check if it has been digitally signed or not. In this article, you will learn how to achieve this task programmatically in Java using Spire.Presentation for Java.
Install Spire.Presentation for Java
First of all, you're required to add the Spire.Presentation.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.
<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.4.5</version> </dependency> </dependencies>
Verify if a PowerPoint Document is Digitally Signed
Spire.Presentation for Java provides the Presentation.isDigitallySigned() method to detect if a PowerPoint document is digitally signed or not. If the method returns true, then it means the document is digitally signed.
The following are the detailed steps to implement this function:
- Create a Presentation instance.
- Load a PowerPoint document using Presentation.loadFromFile() method.
- Detect if the document is digitally signed or not using Presentation.isDigitallySigned() method.
- Java
import com.spire.presentation.Presentation; public class VerifyIfPPTisDigitallySigned { public static void main(String []args) throws Exception { //Create a Presentation instance Presentation ppt = new Presentation(); //Load a PowerPoint document ppt.loadFromFile("Sample.pptx"); //Verify if the document is digitally signed or not if (ppt.isDigitallySigned()) { System.out.println("This document is digitally signed"); } else { System.out.println("This document is not digitally signed"); } } }
Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
Java: Add or Remove Digital Signatures in PowerPoint
A digital signature confirms that the document content originates from the signer and has not been changed. In this article, you will learn how to add a digital signature to your PowerPoint documents as well as remove all digital signatures using Spire.Presentation for Java.
Installl Spire.Presentation for Java
First of all, you're required to add the Spire.Presentation.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.
<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.4.5</version> </dependency> </dependencies>
Add a Digital Signature to PowerPoint
The following are the steps to add a digital signature to a PowerPoint document.
- Create an object of Presentation class.
- Load the sample PowerPoint document using Presentation.loadFromFile() method.
- Add a digital signature to the document using Presentation.addDigitalSignature(String pfxPath, String password, String comments, java.util.Date signTime) method.
- Save the result to a .pptx file using Presentation.saveToFile() method.
- Java
import com.spire.presentation.FileFormat; import com.spire.presentation.Presentation; import java.util.Date; public class AddDigitalSignature { public static void main(String[] args) throws Exception { //Create a Presentation object Presentation presentation = new Presentation(); //Load the sample PowerPoint document presentation.loadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pptx"); //Add a digital signature String pfxPath = "C:\\Users\\Administrator\\Desktop\\MyCertificate.pfx"; String password = "e-iceblue"; String comment = "Modification is not allowed"; presentation.addDigitalSignature(pfxPath,password,comment,new Date()); //Save the result to file presentation.saveToFile("output/AddDigitalSignature.pptx", FileFormat.PPTX_2013); } }
Remove all Digital Signaters from PowerPoint
The following are steps to remove all digital signatures from a PowerPoint document.
- Create an object of Presentation class.
- Load the sample PowerPoint document using Presentation.loadFromFile() method.
- Determine if the document contains digital signatures using Presentation.isDigitallySigned() method.
- Remove all signatures using Presentation.removeAllDigitalSignatures() method.
- Save the result to a .pptx file using Presentation.saveToFile() method.
- Java
import com.spire.presentation.FileFormat; import com.spire.presentation.Presentation; public class RemoveDigitalSignature { public static void main(String[] args) throws Exception { //Create a Presentation object Presentation presentation = new Presentation(); //Load the sample PowerPoint document presentation.loadFromFile("C:\\Users\\Administrator\\Desktop\\AddDigitalSignature.pptx"); //Determine if the document is digitally signed if (presentation.isDigitallySigned() == true) { //Remove all digital signatures presentation.removeAllDigitalSignatures(); } //Save the result to file presentation.saveToFile("output/RemoveDigitalSignature.pptx", FileFormat.PPTX_2013); } }
Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
Java protect presentation slides by setting the property with mark as final
Mark as Final means that the presentation slide is final edition and the author doesn’t want any changes on the document. With Spire.Presentation for Java, we can protect the presentation slides by setting the password. This article demonstrates how to mark a presentation as final by setting the document property MarkAsFinal as true.
import com.spire.presentation.FileFormat; import com.spire.presentation.Presentation; public class MarkAsFinal { public static void main(String[] args) throws Exception { //Create a PPT document and load file Presentation presentation = new Presentation(); presentation.loadFromFile("Sample.pptx"); //Set the document property MarkAsFinal as true presentation.getDocumentProperty().set("_MarkAsFinal", true); //Save the document to file presentation.saveToFile("output/MarkasFinal.pptx", FileFormat.PPTX_2010); } }
Effective screenshot after mark as final for presentation:
Java: Protect or Unprotect PowerPoint Documents
Occasionally, you may need to protect PowerPoint documents. For instance, when you want to prevent unauthorized users from viewing and editing a PowerPoint document. Conversely, sometimes you may also need to unprotect PowerPoint documents. For example, when you wish to make a password-protected PowerPoint document accessible to everyone. In this article, we will introduce how to protect or unprotect PowerPoint documents in Java using Spire.Presentation for Java.
- Protect a PowerPoint Document with a Password
- Mark a PowerPoint Document as Final
- Remove Password Protection from a PowerPoint Document
- Remove Mark as Final Option from a PowerPoint Document
Install Spire.Presentation for Java
First of all, you're required to add the Spire.Presentation.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.
<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.4.5</version> </dependency> </dependencies>
Protect a PowerPoint Document with a Password in Java
You can protect a PowerPoint document with a password to ensure that only the people who have the right password can view it.
The following steps demonstrate how to protect a PowerPoint document with a password:
- Initialize an instance of Presentation class.
- Load a PowerPoint document using Presentation.loadFromFile() method.
- Encrypt the document with a password using Presentation.encrypt() method.
- Save the result document using Presentation.saveToFile() method.
- Java
import com.spire.presentation.FileFormat; import com.spire.presentation.Presentation; public class ProtectPPTWithPassword { public static void main(String []args) throws Exception { //Create a Presentation instance Presentation presentation = new Presentation(); //Load a PowerPoint document presentation.loadFromFile("Sample.pptx"); //Encrypt the document with a password presentation.encrypt("your password"); //Save the result document presentation.saveToFile("Encrypted.pptx", FileFormat.PPTX_2013); } }
Mark a PowerPoint Document as Final in Java
You can mark a PowerPoint document as final to inform readers that the document is final and no further editing is expected.
The following steps demonstrate how to mark a PowerPoint document as final:
- Initialize an instance of Presentation class.
- Load a PowerPoint document using Presentation.LoadFromFile() method.
- Mark the document as final using Presentation.getDocumentProperty().set() method.
- Save the result document using Presentation.SaveToFile() method.
- Java
import com.spire.presentation.FileFormat; import com.spire.presentation.Presentation; public class MarkPPTAsFinal { public static void main(String []args) throws Exception { //Create a Presentation instance Presentation ppt = new Presentation(); //Load a PowerPoint document ppt.loadFromFile("Sample.pptx"); //Mark the document as final ppt.getDocumentProperty().set("_MarkAsFinal", true); //Save the result document ppt.saveToFile("MarkAsFinal.pptx", FileFormat.PPTX_2013); } }
Remove Password Protection from a PowerPoint Document in Java
You can remove password protection from a PowerPoint document by loading the document with the correct password, then removing the password protection from it.
The following steps demonstrate how to remove password protection from a PowerPoint document:
- Initialize an instance of Presentation class.
- Load a PowerPoint document using Presentation.loadFromFile() method.
- Mark the document as final through Presentation.removeEncryption() method.
- Save the result document using Presentation.saveToFile() method.
- Java
import com.spire.presentation.FileFormat; import com.spire.presentation.Presentation; public class RemovePasswordProtectionFromPPT { public static void main(String []args) throws Exception { //Create a Presentation instance Presentation presentation = new Presentation(); //Load a password-protected PowerPoint document with the right password presentation.loadFromFile("Encrypted.pptx", "your password"); //Remove password protection from the document presentation.removeEncryption(); //Save the result document presentation.saveToFile("RemoveProtection.pptx", FileFormat.PPTX_2013); } }
Remove Mark as Final Option from a PowerPoint Document in Java
The mark as final feature makes a PowerPoint document read-only to prevent further changes, if you decide to make changes to the document later, you can remove the mark as final option from it.
The following steps demonstrate how to remove mark as final option from a PowerPoint document:
- Initialize an instance of Presentation class.
- Load a PowerPoint document using Presentation.loadFromFile() method.
- Remove the mark as final option from the document using Presentation.getDocumentProperty().set() method.
- Save the result document using Presentation.saveToFile() method.
- Java
import com.spire.presentation.FileFormat; import com.spire.presentation.Presentation; public class RemoveMarkAsFinalFromPPT { public static void main(String []args) throws Exception { //Create a Presentation instance Presentation ppt = new Presentation(); //Load a PowerPoint document ppt.loadFromFile( "MarkAsFinal.pptx"); //Remove mark as final option from the document ppt.getDocumentProperty().set("_MarkAsFinal", false); //Save the result document ppt.saveToFile("RemoveMarkAsFinal.pptx", FileFormat.PPTX_2013); } }
Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.