Scriptel OmniScript Tutorial 02 - Receiving and Customizing Signature Images

From Scriptel Wiki
Revision as of 17:09, 8 September 2022 by Samuel Lovetro (talk | contribs) (Created page with "==Video tutorial== <embedvideo service="youtube">https://www.youtube.com/watch?v=cjmbjLO-SSU </embedvideo> '''Scriptel OmniScript Tutorial 02 - Receiving and Customizing Sig...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Video tutorial

Scriptel OmniScript Tutorial 02 - Receiving and Customizing Signature Images

Instructions

In this video tutorial we're going to walk through creating a JavaScript application capable of receiving and displaying signature images from Scriptel OmniScript.

Video instructions follow:

You'll need a couple tools to get started.

You'll need a recent web-browser, either Apple Safari 6 or greater, Google Chrome 16 or greater, Microsoft Internet Explorer 10 or greater, Mozilla Firefox 11 or greater, or Opera 12.10 or later.

Next you'll need a text editor: Notepad, G edit, or TextEdit will all work, but pretty much any text editor should do the trick.

Make sure OmniScript is installed and running, and that you have at least one ScripTouch signature capture device hooked up to your computer.

For this example, we're going to assume that you're going to be using an OmniScript instance installed on your local computer.

Step 1: Creating the Example Files

  1. We'll start by creating the files we'll need to make the example work.
  2. Open up a folder and create two new files. We'll create a tutorial HTML file and a tutorial JavaScript file.
  3. Let's open up the HTML file and make a skeleton HTML document.
  4. Add the <doctype> tag to indicate this is an HTML5 application.
  5. Then create the open and close <html> tags.
  6. Next, create the <head> and <body> tags.
  7. Let's give our document a <title> and create a <script> tag that sources in the script file we just created.
  8. Now we'll add an <img> tag that we'll use later to display our signature images.
  9. Now let's add an onload handler to our document body that calls a function we'll create in the JavaScript file in just a moment.
  10. Save the document and open up the JavaScript file.
  11. Create the function we just referenced in the onload handler in the html document.
  12. Double-check and make sure the function matches the one we're calling.

Once that's done we can start writing code.

Step 2: Writing the Code

  1. Let's start by creating a websocket along with a callback for the "connection established," "connection closed," and "data received" events.
  2. We'll put console.log() statements in each of the callbacks so we can verify they're being called when we run the application.
  3. Now, just like in the connecting tutorial, we'll deserialize the JSON messages coming from OmniScript and will handle them by class.
  4. The first class we'll handle is the "connection open" event.
  5. Similar to last time, we'll check to see if the OmniScript server has any open devices.
  6. If it does, we'll go ahead and open the first one.
  7. We'll do this by creating a new "device open" request object and sending it back to OmniScript with the first device's universal unique identifier.
  8. Next we'll handle the "device open" response object.
  9. Just add a console.log() here for now.

Now for the interesting event, the rendered image event. Anytime the "OK" button is hit, OmniScript will render its stored signature buffer as an image and will send it to you.

This means all you need to do to get an image of a signature from your digitizer is to handle this event. Signatures are transferred as data urls which most modern web browsers are capable of displaying as an image.

Let's add a handler for this now, and we'll catch the event and inject the data url into the image we created as part of the html document. That should do it, let's test what we have so far.

Step 3: Testing

  1. Open a web browser and load your web page.
  2. Open the Developer console and check to make sure there aren't any errors, then try to sign on your signature pad and press "OK."
  3. You'll see here when I pressed "OK," I received an error. It looks like I put an extra letter on the last line of my signature handler.
  4. Let's correct that now and try again.

Now when I sign and press "OK," the image of my signature is displayed in the browser. That works, but isn't very flexible. What if i want to change some of the parameters?

Step 4: Change Settings

OmniScript allows you to change your rendering preferences, such as: image type, image size, line color, and pen style.

Let's add some code that pushes our preferences to OmniScript when we open the connection. We'll do this by sending a "render settings update" request to OmniScript.

This object has a lot of properties we can set. Check out the OmniScript documentation for an exhaustive list.

  1. For now let's just change the size of the image to make it a little bit smaller.
  1. Now let's refresh and try again.
  1. You'll notice that after you sign, the signature came out considerably smaller. That's because we changed the scale from the default to 1.

By changing the values you put in the "render settings update" request, you can customize how your signatures are rendered and sent to you.