Hi, I am using group docs with Java Spring application. When i login to the application, I have to upload the document first and then preview it and then add a signature icon and other extra fields like user id, date in the bottom of document before sending it to the recipient for Signature. The recipient will get to know where he has to sign once he opens the document. Is it possible to do it ? Can you please advise ?
Thanks for posting your inquiry.
Your desired functionality can be achieved using a combination of Text and Image signatures. The text signature will be used to add the user ID, date or any other fields, whereas, the image signature will be used to place the signature icon. The following code sample shows how to implement this scenario. Please note that this code is specific for PDF documents, however, you can implement this functionality for other document formats in the similar way (see documentation).
// Set configurations SignatureConfig signConfig = new SignatureConfig(); signConfig.setStoragePath("D:\\Storage\\"); signConfig.setOutputPath("D:\\Output\\"); String fileName = "candy.pdf"; // Instantiating the signature handler SignatureHandler<String> handler = new SignatureHandler<String>(signConfig); // Set up image signature PdfSignImageOptions signImageOptions = new PdfSignImageOptions(signConfig.getStoragePath() + "sign.png"); signImageOptions.setWidth(20); signImageOptions.setHeight(20); // you can change the margins according to your requirements signImageOptions.getMargin().setBottom(20); signImageOptions.setHorizontalAlignment(HorizontalAlignment.Left); signImageOptions.setVerticalAlignment(VerticalAlignment.Bottom); // Set up text signature Date date = new Date(); // You can set desired text here (UserID, date etc.) PdfSignTextOptions signTextOptions = new PdfSignTextOptions("John Smith, " + date.toString()); // you can change the margins according to your requirements signTextOptions.getMargin().setBottom(10); signTextOptions.setHorizontalAlignment(HorizontalAlignment.Left); signTextOptions.setVerticalAlignment(VerticalAlignment.Bottom); signTextOptions.getFont().setFontSize(5); signTextOptions.setHeight(10); // Set up save options SaveOptions saveOptions = new SaveOptions(); saveOptions.setOutputType(OutputType.String); saveOptions.setOutputFileName("signed_output"); // Add signatures to the collection SignatureOptionsCollection collection = new SignatureOptionsCollection(); collection.add(signImageOptions); collection.add(signTextOptions); // Apply signatures to document String signedPath = handler.<String> sign(fileName, collection, saveOptions);
Furthermore, you can also try our open source front end application for signing documents which is available here. You can use this application and modify it as per your requirements. Hope it helps.
Hi , Thank you for the update. I am using the front end application now to add the required texts. But I am facing an issue. The save button is always disabled in this application. I am unable to save my changes. Can you please let me know why this behaviour ? . I have a valid group docs total license and I have also set the application.LicensePath. Can you please advise ?
Thanks for coming back.
We have checked the application at our end but could not reproduce your reported issue. Please make sure that after adding the signature on the document pages, you are applying the signature by clicking on the green tick mark button (see screenshot). Once you have applied the signature, the Save button becomes enable (see screenshot). When you click the Save button, the signed document gets saved in \DocumentSamples\SignatureData\Output folder.
Hi, Thanks for the update. I understood what you said. I will try it out. I have integrated the spring signature code in my spring boot application but when i add a text signature and confirm , i get this thing “Evaluation version etc.”. Here is the image
download.png (483 Bytes)
I am assuming the issue is related to the license. I have a valid license and it’s path has been set in application.LicensePath. Can you please advise how do i set the correct license path ?
I have a spring boot application. I have the license file in F drive and I have set it like this “application.licensePath=F:\GroupDocs.Total.Java.lic”
Hi, Thank you for the support. In Addition, I printed the stack trace while loading the license for signature. Please find the error logs attached. I could not figure it out. Can you please suggest what kind of error it is ?
LicenseError.pdf (65.1 KB)
Thanks for coming back to us.
The API shows this evaluation message when the license is not applied. Therefore, please make sure that you have provided the correct path of the license file in the configurations. Also, please check that the application has access to the location where the license file is placed. Furthermore, if you have updated the license file’s path in configurations then you will have to rebuild the source code. You can easily do this by following the below points:
- Update licensePath’s value in configuration.yml (see example)
- Open Windows PowerShell or Command Prompt and navigate to the project’s root folder
- Build the source code by running the command:
mvn clean spring-boot:run
- Open application’s URL (i.e. http://localhost:8080/signature/) in the browser
Hope it helps.
Thanks for the update. When i used the latest version of group docs signature, the license issue got resolved.
I have one more query. I was able to use both text and image signatures from your Java Spring UI application . Can you please advise me on how to use a digital signature ?
Its good to know that your issue has been resolved.
The digital signature feature of the API uses certificates (.pfx, .cer) to sign the documents. The API also allows setting different parameters of the digital signature for different document formats such as Comments, SignTime etc. Please have a look at this documentation article for the usage of this feature. Furthermore, the option of adding the digital signature is also available in our GroupDocs.Signature for Java - Spring application.
Hi, Thanks for the update. I will look into it. Can i use these options like SignTime and comments in the Java Spring UI application ?
In Addition, Can you please let me know if there is any option to validate if the user has signed the document ?
Consider this case, The sender has uploaded a 5 page document by adding text fields named Signature. The recipient receives the document but he signs on only first page but forgets to sign on other pages. Is there any option to check if the recipient has signed on all the pages ?
Yes, the application provides the feature of adding SignTime and Comments with digital signatures.
GroupDocs.Signature for Java provides the signature verification feature that can be used to fulfill your requirement. For example, the following code sample signs the first page of the Word document with a text signature and then verifies all the pages of the signed document for that text signature. The VerificationResult.isValid() method returns true if all the pages are signed, otherwise, it returns false.
... // Set sign options WordsSignTextOptions signOptions = new WordsSignTextOptions("John Smith"); signOptions.setLeft(10); signOptions.setTop(10); signOptions.setWidth(100); signOptions.setHeight(100); signOptions.setDocumentPageNumber(1); // Set save options SaveOptions saveOptions = new SaveOptions(); saveOptions.setOutputType(OutputType.String); saveOptions.setOutputFileName("signed"); signedPath = handler.<String> sign(fileName, signOptions, saveOptions); // Sign document String signedDocumentPath = handler.<String> sign("sample.docx", signOptions, saveOptions); // Verify the document WordsVerifyTextOptions verifyOptions = new WordsVerifyTextOptions("John Smith"); verifyOptions.setVerifyAllPages(true); VerificationResult result = handler.verify(signedDocumentPath, verifyOptions); System.out.println("Is Verified: " + result.isValid());
At the moment, the signature verification feature is available for the following signature types:
- Text Signature
- Digital Signature
- QR Code Signature
- Barcode Signature
For more details, please visit this documentation article.