DEV Community

E-iceblue Product Family
E-iceblue Product Family

Posted on • Updated on

How to add/remove digital signature to PowerPoint document in Java

Digital signature is a great way to protect the original document has not been changed. Creating digital signature in PowerPoint document becomes one of the most popular way to protect the presentation slides from editing and tampering. Spire.Presentation for java offers Presentation.addDigitalSignature() method and Presentation.removeAllDigitalSignatures() method to add and remove the digital signature.

Installl Spire.Presentation for Java

Firstly, we need to add the Spire.Presentation.jar file as a dependency in our Java program. The JAR file can be downloaded from this link. If we use Maven, we can import the JAR file by adding the following code to the 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>4.9.2</version>
    </dependency>
</dependencies>
Enter fullscreen mode Exit fullscreen mode

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 document to a .pptx file using Presentation.saveToFile() method.
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("sample.pptx");

        //Add a digital signature
        String pfxPath = "Certificate.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);
    }
}
Enter fullscreen mode Exit fullscreen mode

Add digital signature to PowerPoint

Remove all Digital Signatures from PowerPoint

We will remove all digital signatures from a PowerPoint document via the following steps:

  • 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.
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("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);
    }
}
Enter fullscreen mode Exit fullscreen mode

Remove digital signature from PowerPoint
Besides the digital signature, Spire.Presentation for Java also enables developers to encrypt the PowerPoint files with password, set write protection to protect presentation slides. You could check the tutorial links for more information. Thanks for your reading.

Top comments (0)