Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Signature signature = new Signature("sample.pdf");
// Set signature text and appearance
TextSignOptions options = new TextSignOptions("John Smith");
// set signature position
options.setLeft(100);
options.setTop(100);
// set signature rectangle
options.setWidth(100);
options.setHeight(30);
// set text color and Font
options.setForeColor(Color.RED);
SignatureFont signatureFont = new SignatureFont();
signatureFont.setSize(12);
signatureFont.setFamilyName("Comic Sans MS");
options.setFont(signatureFont);
// sign document to file
signature.sign("signed.pdf", options);
// setup configuration
SignatureConfig signConfig =new SignatureConfig();
signConfig.setStoragePath("C:\\Storage");
signConfig.setOutputPath("C:\\Output");
// instantiate the conversion handler
SignatureHandler<String> handler = new SignatureHandler<String>(signConfig);
// setup text signature options
PdfSignTextOptions signOptions = new PdfSignTextOptions("John Smith");
// setup colors settings
signOptions.setBackgroundColor(Color.BLUE);
// setup text color
signOptions.setForeColor(Color.RED);
// setup Font options
signOptions.getFont().setBold(true);
signOptions.getFont().setItalic(true);
signOptions.getFont().setUnderline(true);
signOptions.getFont().setStrikeout(true);
signOptions.getFont().setFontFamily("Arial");
signOptions.getFont().setFontSize(15);
// sign document
SaveOptions saveOptions = new SaveOptions();
saveOptions.setOutputType(OutputType.String);
saveOptions.setOutputFileName("Pdf_TextSignatureFontBackgroundAndColorOptions");
String signedPath = handler.<String>sign("test.pdf", signOptions, saveOptions);
Signature signature = new Signature("sample.docx");
// setup key and passphrase
String key = "1234567890";
String salt = "1234567890";
// create data encryption
IDataEncryption encryption = new SymmetricEncryption(SymmetricAlgorithmType.Rijndael, key, salt);
// setup options with text of signature
MetadataSignOptions options = new MetadataSignOptions();
// set encryption for all metadata signatures for this options
// if you need separate encryption use own MetadataSignature.DataEncryption property
options.setDataEncryption(encryption);
// setup signature metadata
WordProcessingMetadataSignature mdAuthor = new WordProcessingMetadataSignature("Author", "Mr.Scherlock Holmes");
// setup data of document id
WordProcessingMetadataSignature mdDocId = new WordProcessingMetadataSignature("DocumentId", java.util.UUID.randomUUID().toString());
// add signatures to options
options.getSignatures().add(mdAuthor);
options.getSignatures().add(mdDocId);
// sign document to file
signature.sign("MetadataEncryptedText.docx", options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.