How can I convert an electronic signature into a printable image?-VBForums
Results 1 to 6 of 6

Thread: How can I convert an electronic signature into a printable image?

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2016
    Posts
    15

    Question How can I convert an electronic signature into a printable image?

    How can I convert an electronic signature (string) into a printable image?

    The signature response data is a string of up to 2048 characters returned as a series of "strokes".
    Within each stroke is a series of X,Y coordinate points.
    X and Y coordinates are separated by a comma and end with a colon.
    The first point of a stroke is always a "move to" position.
    All subsequent points within a stroke are "draw to" positions.
    The "end stroke point" is simply #,#: which is followed by the first point of the next stroke.


    <?xml version="1.0"?>
    <RStream>
    <CmdResponse>
    <ResponseOrigin>Client</ResponseOrigin>
    <DSIXReturnCode>000000</DSIXReturnCode>
    <CmdStatus>Success</CmdStatus>
    <TextResponse>Success</TextResponse>
    <SequenceNo>0010010010</SequenceNo>
    <UserTrace></UserTrace>
    </CmdResponse>
    <Signature>11,29:12,29:11,29:11,28:10,28:11,28:11,29:12,29:13,30:14,30:15,31:16,32:17,32:18,32:19,33 :20,33:21,34:22,34:24,35:25,35:27,36:28,36:30,37:32,38:34,38:36,39:37,39:39,40:42,41:44,41:46,42:48, 43:50,43:52,44:54,45:56,46:58,46:60,47:62,48:64,48:66,49:68,50:69,50:71,51:73,51:74,51:76,51:77,51:7 9,52:80,52:82,52:83,52:85,51:86,51:87,51:88,51:89,51:90,51:91,51:92,51:93,51:92,50:92,49:93,48:93,47 :93,46:#,#:163,50:162,50:161,50:160,51:159,51:159,52:158,52:158,53:157,53:158,53:158,52:159,51:160,5 0:162,49:164,47:167,45:169,42:172,39:176,37:179,34:183,31:187,28:190,25:194,23:197,20:200,18:203,16: 206,15:208,14:210,13:212,12:214,11:215,11:216,10:217,10:218,10:217,10:216,10:216,11:215,11:214,11:21 3,11:212,11:212,10:211,10:#,#:</Signature>
    <SignMaximumX>228</SignMaximumX>
    <SignMaximumY>63</SignMaximumY>
    </RStream>
    Attached Images Attached Images

  2. #2
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    4,162

    Re: How can I convert an electronic signature into a printable image?

    Which part(s) are you having problems with?
    Parsing the lines from the file?
    Parsing the strings for the coordinates?
    Drawing the coordinates?
    Saving the image to a file?

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2016
    Posts
    15

    Re: How can I convert an electronic signature into a printable image?

    Quote Originally Posted by passel View Post
    Which part(s) are you having problems with?
    Parsing the lines from the file?
    Parsing the strings for the coordinates?
    Drawing the coordinates?
    Saving the image to a file?
    Thank you very much for your quick reply.
    I parsed the string from C# code but how to:
    Drawing the coordinates, and save in memory to print.
    Saving the image to a file? (save to test)


    Code:
    Sub ConvertSignatureDataToImage(Optional SignatureData As String)
        On Error Resume Next
        Dim Signature As String
        Dim X As String
        Dim Y As String
        Dim keepX As String
        Dim keepY As String
        Dim SignMaximumX As Integer
        Dim SignMaximumY As Integer
        Dim stringOfPoints() As String
        Dim beginStroke As Boolean
        
        beginStroke = True
        If IIf(Trim(SignatureData) <> "", Module2.GetXMLElementValue("cmdStatus", SignatureData), "") = "Success" Then
            Signature = Module2.GetXMLElementValue("Signature", SignatureData)
            SignMaximumX = Module2.GetXMLElementValue("SignMaximumX", SignatureData)
            SignMaximumY = Module2.GetXMLElementValue("SignMaximumY", SignatureData)
            
            
            stringOfPoints = Split(Signature, ":")
            For i = 0 To UBound(stringOfPoints)
               If Trim(stringOfPoints(i)) <> "" Then
                  Dim point As String
                  point = stringOfPoints(i).Split(",")
                  X = point(0)
                  Y = point(1)
                  If (X = "#" And Y = "#") Then
                      beginStroke = True
                  Else
                      If beginStroke Then
                          beginStroke = False
                      Else
                           ' DRAW HERE
                      End If
                  End If
                  keepX = X
                  keepY = Y
               End If
            Next
        End If
    End Sub
    Last edited by oxixo; Feb 9th, 2018 at 01:37 PM.

  4. #4
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    4,162

    Re: How can I convert an electronic signature into a printable image?

    Well, the code looks like its along the lines of what I tested earlier.
    I'll post my code and let you figure out how to adapt it for your purposes.
    I used a picturebox to draw in, and didn't use the min/max values which could be used to size the picturebox if desired.
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
      Dim s As String
      s = "<Signature>11,29:12,29:11,29:11,28:10,28:11,28:11,29:12,29:13,30:14,30:15,31:16,32:17,32:18,32:19,33:20,33:21,34:22,34:24,35:25,35:27,36:28,36:30,37:32,38:34,38:36,39:37,39:39,40:42,41:44,41:46,42:48,43:50,43:52,44:54,45:56,46:58,46:60,47:62,48:64,48:66,49:68,50:69,50:71,51:73,51:74,51:76,51:77,51:79,52:80,52:82,52:83,52:85,51:86,51:87,51:88,51:89,51:90,51:91,51:92,51:93,51:92,50:92,49:93,48:93,47:93,46:#,#:163,50:162,50:161,50:160,51:159,51:159,52:158,52:158,53:157,53:158,53:158,52:159,51:160,50:162,49:164,47:167,45:169,42:172,39:176,37:179,34:183,31:187,28:190,25:194,23:197,20:200,18:203,16:206,15:208,14:210,13:212,12:214,11:215,11:216,10:217,10:218,10:217,10:216,10:216,11:215,11:214,11:213,11:212,11:212,10:211,10:#,#:</Signature>"
     ' s = "<Signature>50,40:48,41:45,42:43,43:42,44:40,45:38,46:36,47:34,48:32,49:30,49:28,50:23,50:21,49:19,49:17,48:16,47:14,45:13,44:12,42:11,40:10,37:10,32:11,31:12,29:14,27:17,27:18,26:19,27:21,27:22,28:23,29:25,30:26,31:28,33:29,35:30,37:32,39:33,42:34,45:34,49:35,52:36,56:36,68:35,77:34,81:33,85:#,#:10,85:11,80:13,76:15,72:17,69:19,66:22,63:24,61:26,59:29,58:31,57:34,56:38,56:40,57:44,58:45,59:47,60:48,61:49,62:50,64:51,66:#,#:</Signature>"
      s = Replace(s, "<Signature>", " ")
      s = Replace(s, "</Signature>", " ")
      If Right$(s, 1) = ":" Then Mid$(s, Len(s), 1) = " "
      
      Picture1.ScaleMode = vbPixels
      Picture1.AutoRedraw = True
      Picture1.Cls
      
      Dim sa() As String
      sa = Split(s, ":")
      
      Dim i As Integer
      Dim drawing As Boolean
      Dim coord() As String
      Dim x As Single, y As Single
      
      For i = 0 To UBound(sa)
        If sa(i) = "#,#" Then
          drawing = False
        Else
          If Len(sa(i)) > 3 Then
            coord = Split(sa(i), ",")
            x = Val(coord(0))
            y = Val(coord(1))
            If drawing Then
              Picture1.Line -(Val(coord(0)), Val(coord(1)))
            Else
              Picture1.PSet (Val(coord(0)), Val(coord(1)))
              drawing = True
            End If
          End If
        End If
      Next
      SavePicture Picture1.Image, "C:\c\signature.bmp"
    End Sub

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2016
    Posts
    15

    Re: How can I convert an electronic signature into a printable image?

    Thank you very much passel. I draw test 2 lines. It is correct.

    How to draw signature in memory which no need use PictureBox.
    Because after I receive "XML signature", I will parse and print the signature to Receipt.
    Last edited by oxixo; Feb 9th, 2018 at 03:19 PM.

  6. #6
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    4,162

    Re: How can I convert an electronic signature into a printable image?

    Well, the Printer Object supports drawing, i.e. the Printer.Pset and Printer.Line commands, so you shouldn't have to draw the signature in memory, you could just draw it on the printer.
    You probably need an X,Y offset to add to the points to position the signature where you want, and perhaps need to multiply the coordinates by a scaling factor to size the signature to the size you want.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width