Remove Digital Signatures from PDF in Java

2021-05-24 05:47:36 Written by  support iceblue
Rate this item
(0 votes)

This article shows you how to remove digital signatures from a PDF document using Spire.PDF for Java.

import com.spire.pdf.PdfDocument;
import com.spire.pdf.widget.PdfFieldWidget;
import com.spire.pdf.widget.PdfFormWidget;
import com.spire.pdf.widget.PdfSignatureFieldWidget;

public class RemoveSignature {

    public static void main(String[] args) {

        //Create a PdfDocument object
        PdfDocument pdf = new PdfDocument();

        //Load the sample PDF document
        pdf.loadFromFile("C:\\Users\\Administrator\\Desktop\\Signature.pdf");

        //Get form widgets collection from the document
        PdfFormWidget widgets = (PdfFormWidget) pdf.getForm();

        //Loop through the widgets collection
        for (int i = 0; i < widgets.getFieldsWidget().getList().size(); i++)
        {
            //Get the specific widget
            PdfFieldWidget widget = (PdfFieldWidget)widgets.getFieldsWidget().getList().get(i);

            //Check if the widget is a PdfSignatureFieldWidget
            if (widget instanceof PdfSignatureFieldWidget)
            {
                //Remove the signature widget
                widgets.getFieldsWidget().remove(widget);;
            }
        }

        //Save to file
        pdf.saveToFile("RemoveSignature.pdf");
    }
}

Remove Digital Signatures from PDF in Java

Additional Info

  • tutorial_title:
Last modified on Thursday, 02 September 2021 06:35