This is sample Java program showing how to clear and delete signature fields in a PDF using Qoppa’s PDF library jPDFProcess.

The jPDFProcess’ public API does not give a direct access to deleting fields in a PDF, but when deleting widgets which are the annotation associated with a field on a PDF page, it will also remove the associated field.

This sample java program opens a PDF documents, clears all signatures and remove the signature widgets which will also remove the underlying fields associated with the widgets.

// Load the PDF document
PDFDocument pdfDoc = new PDFDocument ("C:\\myfolder\\signedpdf.pdf", null);
 
/** first clear all the signature fields **/
// get signature fields
Vector<SignatureField> sigFields = pdfDoc.getAcroForm().getSignatureFields(); 
// loop through all the signature fields
for(int count = 0; count < sigFields.size(); count++)
{
  // clear current signature field
  System.out.println("Clearing signature field " + sigFields.get(count).getFieldName());    			
  sigFields.get(count).clearSignature();
}
 
/** now delete all the signature widgets **/         
// loop through pages in the PDF
for(int page = 0; page <pdfDoc.getPageCount(); page++ )
{ 
  // get annotations - which include form field widgets - on the current page 
  Vector<Annotation> annots = pdfDoc.getPage(page).getAnnotations();
  // loop through annotations
  for(int count = 0; count < annots.size(); count++)
  {
      // if this annotation is a signature widget
      if(annots.get(count) instanceof WidgetSignature)
      {
        // remove the signature widget 
        // this also removes any associated signature field
        System.out.println("Signature widget found and removed on page " + (page+1));
        pdfDoc.getPage(page).removeAnnotation(annots.get(count));
      }
   }
 }
// save the PDF (unsigned)
pdfDoc.saveDocument("C:\\myfolder\\unsignedpdf.pdf");

Here is the output for the program above for a PDF that contains 2 digital signatures on the first page:

Clearing signature field Signature1
Clearing signature field Signature2
Signature widget found and removed on page 1
Signature widget found and removed on page 1