Implement Java Stamp Sign Options with GroupDocs.Signature for Document Authenticity

How to Implement Java Stamp Sign Options with GroupDocs.Signature for Java

In today’s digital age, ensuring the authenticity of documents is paramount. Whether you’re a business professional or an individual needing to validate contracts and agreements, adding a stamp signature can lend credibility and security. This tutorial will guide you through setting up stamp sign options using GroupDocs.Signature for Java—a powerful library tailored to meet your document signing needs with ease.

What You’ll Learn:

  • How to configure stamp sign options in Java.
  • Adding inner and outer lines with text and formatting.
  • Practical examples of real-world applications.
  • Key performance considerations when working with GroupDocs.Signature.

Let’s dive into the prerequisites before we start implementing these features.

Prerequisites

Required Libraries, Versions, and Dependencies

To use GroupDocs.Signature for Java, ensure you have:

  • Java Development Kit (JDK): Version 8 or above.
  • Maven/Gradle for dependency management.

For Maven projects, include the following in your pom.xml:

<dependency>
    <groupId>com.groupdocs</groupId>
    <artifactId>groupdocs-signature</artifactId>
    <version>23.12</version>
</dependency>

For Gradle projects, add this to your build.gradle:

implementation 'com.groupdocs:groupdocs-signature:23.12'

You can also directly download the latest version from GroupDocs.Signature for Java releases.

Environment Setup Requirements

  • Ensure JDK is installed and configured.
  • Set up a Maven or Gradle project as per your preference.

Knowledge Prerequisites

  • Basic understanding of Java programming.
  • Familiarity with document handling and signature processes.

Setting Up GroupDocs.Signature for Java

GroupDocs.Signature for Java simplifies integrating digital signing into applications. Here’s how to get started:

  1. Installation: Use Maven or Gradle as shown above, or download the JAR directly from the releases page.
  2. License Acquisition:
    • Free Trial: Download a free trial version from the releases page.
    • Temporary License: Obtain a temporary license for full-feature access via this link.
    • Purchase: For unlimited use, consider purchasing a license here: GroupDocs Purchase.
  3. Basic Initialization:
import com.groupdocs.signature.Signature;

String filePath = "path/to/your/document";
Signature signature = new Signature(filePath);

Implementation Guide

Setting Up Stamp Sign Options

This feature allows you to configure and apply stamp signatures on documents, enhancing their authenticity.

Step 1: Initialize StampSignOptions

import com.groupdocs.signature.options.sign.StampSignOptions;

StampSignOptions signOptions = new StampSignOptions();
signOptions.setHeight(300);
signOptions.setWidth(300);

Explanation: We set the dimensions of our stamp. Adjust height and width as needed.

Step 2: Align and Add Padding

import com.groupdocs.signature.domain.enums.HorizontalAlignment;
import com.groupdocs.signature.domain.enums.VerticalAlignment;
import com.groupdocs.signature.domain.Padding;

signOptions.setVerticalAlignment(VerticalAlignment.Bottom);
signOptions.setHorizontalAlignment(HorizontalAlignment.Right);
Padding padding = new Padding();
padding.setRight(10);
padding.setBottom(10);
signOptions.setMargin(padding);

Explanation: Align the stamp to the bottom-right corner with additional padding for aesthetics.

Step 3: Set Background and Crop Type

import com.groupdocs.signature.domain.Background;
import java.awt.Color;

Background background = new Background();
background.setColor(Color.ORANGE);
signOptions.setBackground(background);

signOptions.setBackgroundColorCropType(StampBackgroundCropType.OuterArea);

Explanation: Customize the stamp’s appearance with a vibrant orange color and define how the background is cropped.

Step 4: Add Image to Stamp

signOptions.setImageFilePath("path/to/stamp/image.jpg");
signOptions.setBackgroundImageCropType(StampBackgroundCropType.InnerArea);
signOptions.setAllPages(true);

Explanation: Use an image for the stamp and apply it across all document pages.

Adding Outer Stamp Lines

Enhance your stamp with decorative lines and text:

Step 1: Create Outer Lines

import com.groupdocs.signature.domain.stamps.StampLine;
import com.groupdocs.signature.domain.SignatureFont;

StampSignOptions signOptions = new StampSignOptions();

// First outer line
StampLine outerLine1 = new StampLine();
outerLine1.setText("* European Union *");
outerLine1.setTextRepeatType(StampTextRepeatType.FullTextRepeat);

SignatureFont font1 = new SignatureFont();
font1.setSize(12);
font1.setFamilyName("Arial");

outerLine1.setFont(font1);
outerLine1.setHeight(30);
outerLine1.setTextColor(Color.WHITE);
outerLine1.setBackgroundColor(Color.BLUE);

signOptions.getOuterLines().add(outerLine1);

Explanation: Add a formatted line with text that repeats fully across the stamp.

Step 2: Separator Line

// Second outer line as a separator
StampLine outerLine2 = new StampLine();
outerLine2.setHeight(2);
outerLine2.setBackgroundColor(Color.WHITE);

signOptions.getOuterLines().add(outerLine2);

Explanation: Insert a simple separator for visual distinction between lines.

Step 3: Add Text with Borders

// Third outer line with additional styling
StampLine outerLine3 = new StampLine();
outerLine3.setText("* Entrepreneur *");
outerLine3.setTextColor(Color.BLUE);

SignatureFont font3 = new SignatureFont();
font3.setSize(15);
outerLine3.setFont(font3);
outerLine3.setHeight(30);

Border innerBorder = new Border();
innerBorder.setColor(Color.DARK_GRAY);
innerBorder.setDashStyle(DashStyle.Dot);
outerLine3.setInnerBorder(innerBorder);

Border outerBorder = new Border();
outerBorder.setColor(Color.BLUE);
outerLine3.setOuterBorder(outerBorder);

signOptions.getOuterLines().add(outerLine3);

Explanation: Add another text line with inner and outer borders for enhanced visibility.

Adding Inner Stamp Lines

Inner lines can contain crucial information or branding:

Step 1: Create Inner Lines

import com.groupdocs.signature.domain.stamps.StampLine;
import com.groupdocs.signature.domain.SignatureFont;

// First inner line
StampLine innerLine1 = new StampLine();
innerLine1.setText("John");
innerLine1.setTextColor(Color.RED);

SignatureFont signFont1 = new SignatureFont();
signFont1.setSize(20);
signFont1.setBold(true);

innerLine1.setFont(signFont1);
innerLine1.setHeight(40);

signOptions.getInnerLines().add(innerLine1);

Explanation: Add a bold, red text line for prominent display.

Step 2: Additional Information

// Second and third inner lines
StampLine innerLine2 = new StampLine();
innerLine2.setText("Smith");
innerLine2.setTextColor(Color.RED);

SignatureFont signFont2 = new SignatureFont();
signFont2.setSize(20);
signFont2.setBold(true);

innerLine2.setFont(signFont2);
innerLine2.setHeight(40);

signOptions.getInnerLines().add(innerLine2);

StampLine innerLine3 = new StampLine();
innerLine3.setText("SSN 1230242424");
innerLine3.setTextColor(Color.MAGENTA);

SignatureFont signFont3 = new SignatureFont();
signFont3.setSize(12);
signFont3.setBold(true);

innerLine3.setFont(signFont3);
innerLine3.setHeight(40);

signOptions.getInnerLines().add(innerLine3);

Explanation: Add additional personal information lines to the stamp, ensuring they are well-formatted and visible.

Practical Applications

  1. Contract Signing: Use stamps for added security in contract documents.
  2. Invoice Authentication: Apply digital stamps on invoices to ensure authenticity.
  3. Legal Document Verification: Enhance legal documents with verifiable signatures.
  4. Business Agreements: Secure business agreements with visible, professional stamp signs.