Last active
January 7, 2016 00:35
-
-
Save Ergin008/2e3c67808b4040c4576b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// specify a document we want signed | |
String SignTest1File = "[PATH/TO/DOCUMENT/TEST.PDF]"; | |
// create a byte array that will hold our document bytes | |
byte[] fileBytes = null; | |
try | |
{ | |
String currentDir = System.getProperty("user.dir"); | |
// read file from a local directory | |
Path path = Paths.get(currentDir + SignTest1File); | |
fileBytes = Files.readAllBytes(path); | |
} | |
catch (IOException ioExcp) | |
{ | |
// TODO: handle error | |
System.out.println("Exception: " + ioExcp); | |
return; | |
} | |
// create an envelope that will store the document(s), field(s), and recipient(s) | |
EnvelopeDefinition envDef = new EnvelopeDefinition(); | |
envDef.setEmailSubject("Please sign this document sent from Java SDK)"); | |
// add a document to the envelope | |
Document doc = new Document(); | |
String base64Doc = Base64.getEncoder().encodeToString(fileBytes); | |
doc.setDocumentBase64(base64Doc); | |
doc.setName("TestFile.pdf"); // can be different from actual file name | |
doc.setDocumentId("1"); | |
List<Document> docs = new ArrayList<Document>(); | |
docs.add(doc); | |
envDef.setDocuments(docs); | |
// add a recipient to sign the document, identified by name and email we used above | |
Signer signer = new Signer(); | |
signer.setEmail("[SIGNER_EMAIL]"); | |
signer.setName("[SIGNER_NAME]"); | |
signer.setRecipientId("1"); | |
// Must set |clientUserId| for embedded recipients and provide the same value when requesting | |
// the recipient view URL in the next step | |
signer.setClientUserId("1001"); | |
// create a |signHere| tab somewhere on the document for the signer to sign | |
// default unit of measurement is pixels, can be mms, cms, inches also | |
SignHere signHere = new SignHere(); | |
signHere.setDocumentId("1"); | |
signHere.setPageNumber("1"); | |
signHere.setRecipientId("1"); | |
signHere.setXPosition("100"); | |
signHere.setYPosition("150"); | |
// can have multiple tabs, so need to add to envelope as a single element list | |
List<SignHere> signHereTabs = new ArrayList<SignHere>(); | |
signHereTabs.add(signHere); | |
Tabs tabs = new Tabs(); | |
tabs.setSignHereTabs(signHereTabs); | |
signer.setTabs(tabs); | |
// add recipients (in this case a single signer) to the envelope | |
envDef.setRecipients(new Recipients()); | |
envDef.getRecipients().setSigners(new ArrayList<Signer>()); | |
envDef.getRecipients().getSigners().add(signer); | |
// send the envelope by setting |status| to "sent". To save as a draft set to "created" | |
envDef.setStatus("sent"); | |
try | |
{ | |
// use the |accountId| we retrieved through the Login API to create the Envelope | |
String accountId = loginAccounts.get(0).getAccountId(); | |
// instantiate a new EnvelopesApi object | |
EnvelopesApi envelopesApi = new EnvelopesApi(); | |
// call the createEnvelope() API to make the signature request live and ready to be signed | |
EnvelopeSummary envelopeSummary = envelopesApi.createEnvelope(accountId, envDef); | |
envelopeId.append( envelopeSummary.getEnvelopeId() ); | |
System.out.println("EnvelopeSummary: " + envelopeSummary); | |
} | |
catch (com.docusign.esign.client.ApiException ex) | |
{ | |
System.out.println("Exception: " + ex); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment