Implement custom serialization with QR-code signatures
Implement custom serialization with QR-code signatures
Leave feedback
GroupDocs.Signature provides ability to embed into QR-code signature custom objects. This feature is implemented over object serialization to string and further encryption. There is ability to provide custom serialization. This procedure requires implementation of interface IDataSerializer with two methods to serialize (serialize) and de-serialize (deserialize) data.
Here are the steps to embed into QR-code text with custom serialization with GroupDocs.Signature:
Implement custom data encryption class that implements IDataSerializer interface.
Define class with serialization attribute created in step above, specify if needed class attributes (like custom serialization attribute, custom encryption attribute), specify attributes for properties like FormatAttribute to specify serialization name and display format, same as SkipSerializationAttribute to mark property of class as not serialize
Create new instance of Signature class and pass source document path as a constructor parameter.
This example shows how to specify custom serialization class. This class could be implemented also as Attribute (optional) to specify as class attribute.
This example shows how to define custom class with serialization and encryption properties and setup Format attributes for properties.
publicstaticclassDocumentSignatureData{publicStringgetID(){returnID;}publicvoidsetID(Stringvalue){ID=value;}@FormatAttribute(propertyName="SignID")publicStringID;publicfinalStringgetAuthor(){returnAuthor;}publicfinalvoidsetAuthor(Stringvalue){Author=value;}@FormatAttribute(propertyName="SAuth")publicStringAuthor;//JAVA-added public wrapper for internalized property accessor
publicfinaljava.util.DategetSigned(){returnSigned;}publicfinalvoidsetSigned(java.util.Datevalue){Signed=value;}@FormatAttribute(propertyName="SDate",propertyFormat="yyyy-MM-dd")publicjava.util.DateSigned=newjava.util.Date();publicfinaljava.math.BigDecimalgetDataFactor(){returnDataFactor;}publicfinalvoidsetDataFactor(java.math.BigDecimalvalue){DataFactor=value;}@FormatAttribute(propertyName="SDFact",propertyFormat="N2")publicjava.math.BigDecimalDataFactor=newjava.math.BigDecimal(0.01);}
Sign documents with custom encrypted objects and values into QR-code signatures
This example shows how to add custom object into metadata signature to Image document.
Signaturesignature=newSignature("sample.pdf");// create custom data encryption
IDataEncryptionencryption=newCustomXOREncryption();// create custom object
DocumentSignatureDatadocumentSignature=newDocumentSignatureData();documentSignature.setID(java.util.UUID.randomUUID().toString());documentSignature.setAuthor(System.getenv("USERNAME"));documentSignature.setSigned(newjava.util.Date());documentSignature.setDataFactor(newjava.math.BigDecimal("11.22"));// setup QR-Code options
QrCodeSignOptionsoptions=newQrCodeSignOptions();// set custom object to serialize to QR Code
options.setData(documentSignature);// QR-code type
options.setEncodeType(QrCodeTypes.QR);// specify serialization encryption
options.setDataEncryption(encryption);// locate and aligh signature
options.setHeight(100);options.setWidth(100);options.setVerticalAlignment(VerticalAlignment.Bottom);options.setHorizontalAlignment(HorizontalAlignment.Right);Paddingpadding=newPadding();padding.setRight(10);padding.setBottom(10);options.setMargin(padding);// sign document to file
SignResultsignResult=signature.sign("QRCodeCustomSerialization.pdf",options);// analyzing result
System.out.print("List of newly created signatures:");intnumber=1;for(BaseSignaturetemp:signResult.getSucceeded()){System.out.print("Signature #"+number+++": Type: "+temp.getSignatureType()+" Id:"+temp.getSignatureId()+",Location: "+temp.getLeft()+"x"+temp.getTop()+". Size: "+temp.getWidth()+"x"+temp.getHeight());}
More resources
GitHub Examples
You may easily run the code above and see the feature in action in our GitHub examples:
Along with full-featured .NET library we provide simple, but powerful free Apps. You are welcome to eSign PDF, Word, Excel, PowerPoint documents with free to use online GroupDocs Signature App.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.