nserror | Posts: 18

Possible to create a template entirely programmatically?

0 votes
We have a need to create a transaction entirely programmatically without displaying any type of UI. To my knowledge this is possible through the use of templates. But as far as I can ascertain, templates needed to be created by hand in advance. Is there a way to generate templates programmatically behind the scenes? By that I mean passing in a document and specifying coordinates / a location on a certain page to place the signature field and then being able to use that result to create a transaction and send it out without there ever needing to be human interaction? Thanks

Duo_Liang | Posts: 3776

Reply to: Possible to create a template entirely programmatically?

1 votes
Hi nserror, Sure, template allows you to store document at OneSpan Sign side and quickly create transactions if changes are minimal. Below sample code shows you how to create a template where leaves signers placeholders from scratch and send a new transaction on this template byreplacing signers with concrete recipients.
EslClient eslClient = new EslClient(API_KEY, API_URL);
                
            DocumentPackage template = PackageBuilder.NewPackageNamed("My template from scratch .NET SDK")
                  .WithSigner(SignerBuilder.NewSignerPlaceholder(new Placeholder("PlaceholderId1")))
                  .WithDocument(DocumentBuilder.NewDocumentNamed("doc1")
                          .FromFile("your_file_path")
                          .WithSignature(SignatureBuilder.SignatureFor(new Placeholder("PlaceholderId1"))
                                .OnPage(0)
                                .AtPosition(100,100))
                          )
                  .Build();


            PackageId templateId = eslClient.CreateTemplate(template);
            Debug.Print("templateId Id: " + templateId);


            DocumentPackage newPackage = PackageBuilder.NewPackageNamed("Package created from template")
                                        .WithSigner(SignerBuilder.NewSignerWithEmail("[email protected]")
                                                .WithFirstName("singer1 firstname")
                                                .WithLastName("signer2 lastname")
                                                .Replacing(new Placeholder("PlaceholderId1")))
                                       .Build();


            PackageId packageFromTemplate = eslClient.CreatePackageFromTemplate(templateId, newPackage);
            Debug.Print("packageFromTemplate Id: " + packageFromTemplate);
            eslClient.SendPackage(packageFromTemplate);
Hope this could help! Duo

mwilliams | Posts: 957

Reply to: Possible to create a template entirely programmatically?

1 votes
You can also do this directly without using a template, since you're wanting to avoid the designer, the only reason to create a template would be to avoid loading the document each time. You can also use our extraction capabilities, like text tags, position extraction, or document extraction to place your fields and signatures in a more automated fashion than figuring out the x/y coordinates.

nserror | Posts: 18

Reply to: Possible to create a template entirely programmatically?

0 votes
This is great information. Thank you both. May I ask, is the sample code provided above valid in version 10?

Duo_Liang | Posts: 3776

Reply to: Possible to create a template entirely programmatically?

0 votes
Hi nserror, No, unfortunately, from my knowledge, there are many design changes between v10 and v11 SDK. And BTW, both classic sandbox and production environments have been migrated to version 11.18.2, so you probably want to update to the corresponding SDK. If you want to update your SDK, I can help you with the code changes. Or you want to stick with v10 SDK, you can tell me your SDK version and I can create some sample code for you. Duo

Hello! Looks like you're enjoying the discussion, but haven't signed up for an account.

When you create an account, we remember exactly what you've read, so you always come right back where you left off