Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
Last active June 18, 2019 08:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GroupDocsGists/dfcb0f5756c43297d979dfa585d2fba0 to your computer and use it in GitHub Desktop.
Save GroupDocsGists/dfcb0f5756c43297d979dfa585d2fba0 to your computer and use it in GitHub Desktop.
//For complete examples and data files, please go to https://github.com/groupdocs-signature/GroupDocs.Signature-for-Java
// setup signature configuration
SignatureConfig signConfig = new SignatureConfig();
signConfig.setStoragePath("\\Storage");
signConfig.setOutputPath("\\Output");
// instantiate the signature handler
SignatureHandler<String> handler = new SignatureHandler<String>(signConfig);
// setup options
WordsStampSignOptions signOptions = new WordsStampSignOptions();
signOptions.setHeight(100);
signOptions.setWidth(300);
signOptions.setBackgroundColorCropType(StampBackgroundCropType.OuterArea);
// inner square lines
StampLine line0 = new StampLine();
line0.setText("PAID");
line0.setTextColor(Color.WHITE);
line0.getFont().setFontSize(32);
line0.getFont().setBold(true);
line0.setHeight(100);
//Set radius of square corner
line0.setOuterBorder(new SquareBorderLine(new Corners(25)));
line0.getOuterBorder().setColor(Color.GRAY);
line0.getOuterBorder().setWeight(2);
line0.setBackgroundColor(Color.GRAY);
signOptions.getInnerLines().add(line0);
SaveOptions saveOptions = new SaveOptions();
saveOptions.setOutputType(OutputType.String);
saveOptions.setOutputFileName("Stamp_RoundedCorners");
// sign document
String signedPath = handler.<String>sign("test.docx", signOptions, saveOptions);
System.out.println("Signed file path is: " + signedPath);
//For complete examples and data files, please go to https://github.com/groupdocs-signature/GroupDocs.Signature-for-.NET
// setup key and passphrase
string key = "1234567890";
string salt = "1234567890";
// create data encryption
IDataEncryption encryption = new SymmetricEncryption(SymmetricAlgorithmType.Rijndael, key, salt);
// setup Signature configuration
SignatureConfig signConfig = new SignatureConfig
{
StoragePath = @"c:\GroupDocs\Test\Storage",
OutputPath = @"c:\GroupDocs\Test\Output"
};
// instantiating the signature handler
SignatureHandler handler = new SignatureHandler(signConfig);
// setup options with text of signature
WordsMetadataSignOptions signOptions = new WordsMetadataSignOptions();
// create custom object
DocumentSignature signature = new DocumentSignature()
{
ID = Guid.NewGuid().ToString(),
Author = Environment.UserName,
Signed = DateTime.Now,
DataFactor = 11.22M
};
// specify different Metadata Signatures and add them to sigature collection
// add object as metadata signature
WordsMetadataSignature mdDocument = signOptions.AddSignature("DocumentSignature", signature);
// set encryption
mdDocument.DataEncryption = encryption;
// sign document
string signedPath = handler.Sign<string>("test.docx", signOptions,
new SaveOptions { OutputType = OutputType.String, OutputFileName = "SignedMedataDataEncrypted.docx" });
Console.WriteLine("Signed file path is: " + signedPath);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment