webPDF Webservices Signature

Minimum Requirements

  • Java version: 7
  • webPDF version: 7
  • wsclient version: 1

Apply a Signature to PDF Documents

If you want to use the webPDF Signature webservice operation, you can do so via the webPDF wsclient library.

Important note: The following coding example is based on the webPDF wsclient library.

Preparing the Signature Webservice

First, create a REST or SOAP session. Then use the WebServiceFactory to create either a SignatureWebService object for SOAP or a SignatureRestWebService object for REST.

SOAP:

SignatureWebService signatureWebService =
WebServiceFactory.createInstance(session, WebServiceType.SIGNATURE);

REST:

SignatureRestWebService signatureWebService =
WebServiceFactory.createInstance(session, WebServiceType.SIGNATURE);

Pass a RestDocument or SoapDocument to the webservice via setDocument().

What Is the Signature Webservice?

The Signature webservice is a webPDF server endpoint that allows you to add digital signatures to PDF documents.

You can retrieve the SignatureType operation like this:

SignatureType signatureType = signatureWebService.getOperation();

The add Object

This object contains the settings for adding a signature:

SignatureType.Add add = new SignatureType.Add();
signatureType.setAdd(add);

appendSignature (default: true)

Defines whether existing signatures should be preserved:

add.setAppendSignature(true);

certificationLevel (default: "noChanges")

Signature level via CertificationLevelType:

  • NONE: sign without certifying, further changes remain possible
  • NO_CHANGES: certify and prevent further changes
  • FORM_FILLING_AND_SIGNATURES: certify and allow form filling and signatures
  • FORM_FILLING_AND_SIGNATURES_AND_ANNOTATIONS: also allow annotations
add.setCertificationLevel(CertificationLevelType.FORM_FILLING_AND_SIGNATURES);

contact (default: "")

Name of the signer:

add.setContact("John Doe");

fieldName (default: "Signature1")

Name of the signature field:

add.setFieldName("SignatureField");

keyName (default: "")

Alias of the key used for signing:

add.setKeyName("keyAlias");

More information: Keystore documentation

keyPassword (default: "")

Password for accessing the private key:

add.setKeyPassword("keyPassword");

reason (default: "")

Reason for the signature:

add.setReason("demonstration for wsclient blog article");

location (default: "")

Location of the signature:

add.setLocation("Main Street 0, Anytown, USA");

The appearance Object

Visual properties of the signature:

SignatureType.Add.Appearance appearance = new SignatureType.Add.Appearance();
add.setAppearance(appearance);

page (default: 1)

Page on which the visible signature is displayed:

appearance.setPage(1);

identifier (default: "")

Text in the right-hand area of the signature:

appearance.setIdentifier("right field of signature text");

name (default: "")

Text in the left-hand area of the signature:

appearance.setName("left area of signature");

The identifierElements Object

Defines the elements shown in the visible signature:

SignatureIdentifierType identifier = new SignatureIdentifierType();
appearance.setIdentifierElements(identifier);

All of the following options default to true:

identifier.setShowCommonName(true);
identifier.setShowCountry(true);
identifier.setShowDate(true);
identifier.setShowLocal(true);
identifier.setShowMail(true);
identifier.setShowName(true);
identifier.setShowOrganisationUnit(true);
identifier.setShowSignedBy(true);
identifier.setShowState(true);

The image Object

This object defines a background graphic for the visible signature:

SignatureImageType image = new SignatureImageType();
appearance.setImage(image);

position (default: center)

Position of the graphic via SignatureImagePositionType:

  • CENTER
  • LEFT
  • RIGHT
image.setPosition(SignatureImagePositionType.CENTER);

opacity (default: 50)

Opacity in percent:

image.setOpacity(60);

The data Object

Passes the image data as Base64:

SignatureFileDataType imageData = new SignatureFileDataType();
image.setData(imageData);
imageData.setValue(Base64.encodeBase64(
FileUtils.readFileToByteArray(new File("image.png"))
));

The position Object

Defines the position and size of the visible signature:

SignaturePositionType position = new SignaturePositionType();
appearance.setPosition(position);
  • x (default: 10 mm from the left): position.setX(10F);
  • y (default: 10 mm from the bottom): position.setY(10F);
  • width (default: 80 mm): position.setWidth(80F);
  • height (default: 40 mm): position.setHeight(60F);

coordinates (default: "user")

Coordinate system via CoordinatesType:

  • USER: origin at the top left
  • PDF: origin at the bottom left
position.setCoordinates(CoordinatesType.USER);

metrics (default: "mm")

Unit via MetricsType:

  • MM: millimeter
  • PX: pixel
position.setMetrics(MetricsType.MM);

Example Webservice Call (SOAP)

try (
// Set up a session with the webPDF server (SOAP in this example):
SoapSession session = SessionFactory.createInstance(
WebServiceProtocol.SOAP,
new URL("https://localhost:8080/webPDF/")
)
) {
// Webservice call and processing
}

More Information

More coding examples for the wsclient library are available here.