Tools/materials
PDF test document
Code Compilation Environment: Ideas
Jdk: 1.8.0
PDF library: freespire.pdf.jar4.4. 1
operational approach
0 1
Import jar files into Java programs, as shown in the figure below:
Note: As shown in the figure, it shows the effect of manually downloading the jar package and then decompressing the importer (you can search and download it yourself); In addition, you can download the import through maven repository. In this way, it is necessary to configure the maven warehouse path and specify the jar version (as shown below) in the pom.xml file, and import it after configuration.
storehouse
storehouse
idcom.e-iceblue/id
Global resource locator (Uniform Resource Locator)
/repository
/repository
dependent state
dependent state
groupId-ice blue/groupId
spire.pdf.free
Version 4. 4. 1/ version
/dependency
/dependency
02
Type the following code in the Java program:
import com . spire . pdf . pdf document;
import com . spire . pdf . widget . pdffieldwidget;
import com . spire . pdf . widget . pdf form widget;
import com . spire . pdf . widget . pdfsignaturefield widget;
publicclassDeleteSignature{
publicstaticvoidmain(String[]args){
//create a PdfDocument object.
PdfDocumentpdf = newPdfDocument();
//load PDF document
pdf . loadfromfile(" add signature . pdf ");
//get the formwidget collection from the document.
PdfFormWidgetwidgets =(PdfFormWidget)pdf . getform();
//Traverse each element in the collection.
for(inti = 0; iwidgets.getFieldsWidget()。 getList()。 size(); i++)
{
//Get the specified widget
PdfFieldWidgetwidget =(PdfFieldWidget)widgets . getfieldswidget()。 getList()。 get(I);
//Determines whether the widget is a PdfSignatureFieldWidget.
if(widgetinstanceofPdfSignatureFieldWidget)
{
//Delete the digital signature widget
widgets.getFieldsWidget()。 Remove (widget);
}
}
//Save the document
pdf . savetofile(" remove signature . pdf ");
pdf . dispose();
}
}
03
Execute the program, and you can view the signature deletion effect in the generated result document, as shown in the following figure: