Digital signatures allow you to sign business documents electronically and remove the hassle of printing, signing, and scanning them. Inserting digital signatures into documents is commonly called electronic signing (or e-signing). eSigns are not only convenient to apply, but they also ensure confidentiality and promote a paperless culture by avoiding printing. Several types of electronic signatures are used for different legal, business, and personal files, as you can incorporate them into documents and images for signing agreements, finalizing contracts, and more.
An electronic signature could also be thought of as a mathematical scheme for demonstrating not only the authenticity but also the integrity of digitally processed files. The native eSign APIs of GroupDocs.Signature for .NET and Java are a must-have for software developers who want to build fully flexible signing apps for popular file formats such as PDF, Microsoft Office, and OpenOffice documents, and images. The secure digital signature APIs for business documents let you add, search, update, or delete multiple types of signatures to your documents and images.
Please review the following information related to API setup before you start signing PDFs and other files with the help of the digital signature APIs for .NET and Java.
We will now check some of the practical use cases of the cross-platform digital signature APIs for multiple file formats.
Adding an electronic signature, or e-signature to a document is a great way to make sure that the document is valid and can be used for legal, or other specific purposes. e-Signs have mostly replaced the earlier practice of manually signing contracts or legal documents with a pen and paper. An e-signature can be as simple as electronically typing your name into a document or as complex as creating a digital signature and injecting it into the document. GroupDocs.Signature API for digital signing support adding a host of different signature types allowing developers to build apps for signing PDF, MS Office files, and images in .NET and Java. This section will show how to add these signatures to your data files.
using (Signature signature = new Signature("sample.pdf")) { TextSignOptions options = new TextSignOptions("John Smith") { // set signature position Left = 100, Top = 100, // set signature rectangle Width = 100, Height = 30, // set Text color and Font ForeColor = Color.Red, Font = new SignatureFont { Size = 12, FamilyName = "Comic Sans MS" } }; // sign document to file signature.Sign("sample_signed.pdf", options); }
Signature signature = new Signature("sample.pdf"); 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("sample_signed.pdf", options);
using (Signature signature = new Signature("sample.pdf")) { // initialize digital option with certificate file path DigitalSignOptions options = new DigitalSignOptions("certificate.pfx") { // optional image setup (file path) ImageFilePath = "sample.jpg", // set signature position Left = 100, Top = 100, // set Password = "1234567890" }; signature.Sign("sampleSigned.pdf", options); }
Signature signature = new Signature("sample.pdf"); DigitalSignOptions options = new DigitalSignOptions("certificate.pfx"); // optional image setup (file path) options.setImageFilePath("sample.jpg"); options.setLeft(100); options.setTop(100); options.setPassword("1234567890"); // sign document to file signature.sign("sampleSigned.pdf", options);
You can also add stamp, barcode, QR code, and metadata e-signatures to your documents using the digital signature APIs for .NET and Java. If you are a .NET developer, please check out more types of eSignatures and how to add them to your .NET signature solutions. Similarly, if you are a Java developer, you have different virtual signing options for the Java platform too.
While working with PDF, Microsoft Office, OpenOffice, or image files, you may need to update the e-signatures added to these files. It could be challenging if you are up against large volumes of file data but important at the same time to keep document integrity intact. One of the best methods of handling this is automating the modification process by developing a software module that systematically updates the electronic signatures used to sign business documents. This is where GroupDocs.Signature APIs are extremely useful. These high-performance, native digital signature APIs for .NET and Java pack a powerful feature set to update your e-signs easily. In this section, we will deal with updating the text signature and image signatures.
// Passing the document to class constructor in which the signature will be updated using (Signature signature = new Signature("sampleSigned.pdf")) { TextSearchOptions options = new TextSearchOptions(); // search for text signatures in document Listsignatures = signature.Search (options); if(signatures.Count > 0) { TextSignature textSignature = signatures[0]; // change Text property textSignature.Text = "John Walkman"; // change position textSignature.Left = textSignature.Left + 10; textSignature.Top = textSignature.Top + 10; // change size. Please note not all documents support changing signature size textSignature.Width = 200; textSignature.Height = 100; bool result = signature.Update(textSignature); if(result) { Console.WriteLine($"Signature with Text '{textSignature.Text}' was updated in the document ['{fileName}']."); } else { Console.WriteLine($"Signature was not updated in the document! Signature with Text '{textSignature.Text}' was not found!"); } } }
// Pass the document to class constructor in which the signature will be updated using (Signature signature = new Signature("sampleSigned.pdf")) { ImageSearchOptions options = new ImageSearchOptions(); // search for image signatures in document Listsignatures = signature.Search (options); if(signatures.Count > 0) { ImageSignature imageSignature = signatures[0]; // change Image properties signatureToUpdate.Top = 200; signatureToUpdate.Left = 200; signatureToUpdate.Width = 300; signatureToUpdate.Height = 150; bool result = signature.Update(imageSignature); if(result) { Console.WriteLine($"Signature with Top '{imageSignature.Top}' was updated in the document ['{fileName}']."); } else { Console.WriteLine($"Signature was not updated in the document! Signature with Top '{imageSignature.Top}' was not found!"); } } }
Signature signature = new Signature("sampleSigned.pdf"); try { TextSearchOptions options = new TextSearchOptions(); // search for text signatures in document Listsignatures = signature.search(TextSignature.class, options); if (signatures.size() > 0) { TextSignature textSignature = signatures.get(0); // change Text property textSignature.setText("John Walkman"); // change position textSignature.setLeft(textSignature.getLeft() + 50); textSignature.setTop(textSignature.getTop() + 50); // change size. Please note not all documents support changing signature size textSignature.setWidth(200); textSignature.setHeight(100); boolean result = signature.update("sampleSigned.pdf",textSignature); if (result) { System.out.print("Signature with Text '" + textSignature.getText() + "' was updated in the document ['sampleSigned.pdf']."); } else { System.out.print("Signature was not updated in the document! Signature with Text '" + textSignature.getText() + "' was not found!"); } } } catch (Exception e) { throw new GroupDocsSignatureException(e.getMessage()); }
using (Signature signature = new Signature("sampleSigned.pdf")) { ImageSearchOptions options = new ImageSearchOptions(); // search for image signatures in document Listsignatures = signature.Search (options); if(signatures.Count > 0) { ImageSignature imageSignature = signatures[0]; // change Image properties signatureToUpdate.Top = 200; signatureToUpdate.Left = 200; signatureToUpdate.Width = 300; signatureToUpdate.Height = 150; bool result = signature.Update(imageSignature); if(result) { Console.WriteLine($"Signature with Top '{imageSignature.Top}' was updated in the document ['{fileName}']."); } else { Console.WriteLine($"Signature was not updated in the document! Signature with Top '{imageSignature.Top}' was not found!"); } } }
Searching for the eSigns added to a document lets you verify the authenticity of the document. If you are working in a distributed team, and regularly deal with different kinds of files, the best way would be to use a tool that not only equips you with adding or making signatures but also manipulating and searching them when needed. Based on the search results, any files with the esigns missing could then be re-evaluated and processed accordingly. GroupDocs native .NET and Java digital signature APIs include signature searching features for PDF and other documents, spreadsheets, presentations, and many more data formats. In this section, you will be checking how, in addition to the ability to integrate digital signing in .NET and Java, you can also search for a few different types of e-signatures using the reliable GroupDocs APIs.
using (Signature signature = new Signature("sample.pdf")) { // search document Listsignatures = signature.Search (SignatureType.Image); Console.WriteLine($"\nSource document ['{fileName}'] contains following image signature(s)."); // output signatures foreach (ImageSignature imageSignature in signatures) { Console.WriteLine($"Image signature found at page {imageSignature.PageNumber} with size {imageSignature.Size}. Created {imageSignature.CreatedOn}, modified {imageSignature.ModifiedOn}"); } }
Signature signature = new Signature(sample.pdf); // setup search options TextSearchOptions options = new TextSearchOptions(); // specify as true to search all pages of a document options.setAllPages(true); // search only page with specified number options.setPageNumber(1); // specify text math type options.setMatchType(TextMatchType.Contains); // specify text to search options.setText("John Smith"); // search for text signatures in document Listsignatures = signature.search(TextSignature.class,options); // output signatures for (TextSignature textSignature : signatures) { if (textSignature != null) { System.out.print("Found Text signature at page "+sign.getPageNumber()+" with type ["+sign.getSignatureImplementation()+"] and text '"+sign.getText()+"'."); System.out.print("Location at "+sign.getLeft()+"-"+sign.getTop()+". Size is "+sign.getWidth()+"x"+sign.getHeight()+"."); } }
When you delete your electronic signature from a document, it's important to understand why you're doing it and the best way to do it. Deleting electronic signatures from documents could be required for a variety of reasons. For instance, the document may no longer be needed or the signer may no longer have a valid reason to keep their signature on the document. Alternatively, the document may have been changed or updated deeming the signature invalid. Regardless of the reasons, GroupDocs.Signature for .NET and Java APIs have the solutions for you. This section will cover how you can remove e-signs from documents using the API for generating and managing digital signatures.
// initialize Signature instance using (Signature signature = new Signature("signed.pdf")) { TextSearchOptions options = new TextSearchOptions(); Listsignatures = signature.Search (options); List signaturesToDelete = new List (); // collect signatures to delete foreach (TextSignature temp in signatures) { if (temp.Text.Contains("John")) { signaturesToDelete.Add(temp); } } // delete signatures DeleteResult deleteResult = signature.Delete(signaturesToDelete); if (deleteResult.Succeeded.Count == signaturesToDelete.Count) { Console.WriteLine("All signatures were successfully deleted!"); } else { Console.WriteLine($"Successfully deleted signatures : {deleteResult.Succeeded.Count}"); Console.WriteLine($"Not deleted signatures : {deleteResult.Failed.Count}"); } Console.WriteLine("List of deleted signatures:"); foreach (BaseSignature temp in deleteResult.Succeeded) { Console.WriteLine($"Signature# Id:{temp.SignatureId}, Location: {temp.Left}x{temp.Top}. Size: {temp.Width}x{temp.Height}"); } }
// initialize Signature instance Signature signature = new Signature("signed.docx"); ImageSearchOptions options = new ImageSearchOptions(); Listsignatures = signature.search(ImageSignature.class, options); List signaturesToDelete = new ArrayList (); // collect signatures to delete for (ImageSignature temp : signatures) { if (temp.getSize() > 10000) { signaturesToDelete.add(temp); } } // delete signatures DeleteResult deleteResult = signature.delete("signed.docx",signaturesToDelete); if (deleteResult.getSucceeded().size() == signaturesToDelete.size()) { System.out.print("All signatures were successfully deleted!"); } else { System.out.print("Successfully deleted signatures : "+deleteResult.getSucceeded().size()); System.out.print("Not deleted signatures : "+deleteResult.getFailed().size()); } System.out.print("List of deleted signatures:"); for(BaseSignature temp : deleteResult.getSucceeded()) { System.out.print("Signature# Id:"+temp.getSignatureId()+", Location: "+temp.getLeft()+"x"+temp.getTop()+". Size: "+temp.getWidth()+"x"+temp.getHeight()); }
GroupDocs.Signature APIs provide many more advanced document e-signature manipulation options for .NET and for Java too. If you are looking for signing PDF, DOCX, PPTX, XLSX, ODS, OTS, or JPEG files on the go, please try the Free Online Digital Signing Apps of GroupDocs.