Save JSON Signature string in Memo for printing

Post Reply
User avatar
TimStone
Posts: 2956
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA
Has thanked: 25 times
Been thanked: 2 times
Contact:

Save JSON Signature string in Memo for printing

Post by TimStone »

In a JSON response, I am receiving a "signature" data string. It is base64 encoded png format. IT IS NOT A FILE. It is a string.

I need to store this in a MEMO field, and later print it on an invoice.

For printing, I use the PrintImage( ) method from the printer class in FWH.

What would be the proper way to store this string in the memo field, and then retrieve it for printing as an image.

Here is a sample response string:

Code: Select all | Expand


             "SignatureData": "iVBORw0KGgoAAAANSUhEUgAAALcAAACRCAYAAACBmym0AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAN6SURBVHhe7dcBbuM4EEXB3P/SWRAD7jLazliyRZvsrgL+Adx8EOCvb0hK3KQlbtISN2mJm7TETVriJi1xk5a4SUvcpCVulvP19fXXnSVuPiqK99HOEjdvE4Ua7S7iZooo2mgziZtbROEe927i5rIo3ONWIG4eiuI9bkXi5oco3ON2Ie7ioniP25W4i4niHZeJuJOLAh6XmbiTiQIeV4m4NxbFe1xl4t5IFO9x/Mc1FhbFO46/c6EFRSG3cY2LLUTM93LBBYh6Dpf8MGHP45ofIur5XPVDRD2f65KWuElL3KQl7hf5U7guL/KkMWpxr8mLXCTqfXiZk0S9Hy/0gKj35aUCUdBt7MWLDQSdS/nXi4JuY39lX1HQ+ZV6UUHXkv51o6DbyC/lK0cxt1FLmhePYm6jrq1fP4q5DZrtSohi7oPR8kVEEY+D3yxZRxRxH5y1RC1RxOPgGR8tJwq5De7w9pKimNvgbm+rStC829TCoqDb4B2mlCZoVnBrdYJmJbcUKGpW9FKJomZlTxcpbFZ3uUpRs4tLdYqanTwVN+zgdKm+2uzmctywC3GTlloX1j8oPirPcbWFjXGL/DrX2oTQr3OhzYj8PJfZlMgfc5EEhB5zhUQE/pMLJCTyP8SdWPXAxZ1c5cDFXUDVwMVdRMXAxV3IGHiFyMVdkLhJS9yk1MMWN+lUCbsRdyGVvtqNuIuoFnYj7gIqht2Iu4CKYTfiTq5q2I24E+thi5tUqofdiDshYf8h7kTGqKuH3bhAAqKOucTmhP0719iUqB9zlc2I+jzX2cQx6oxh3/3bxL248cHvfPiVzPqN4l7QrMdezezfKe4FzXrsFYy/bdwM4ma6KOa22cTNNJ8IeiRubvfpqDtxc5tVou7EzctWi7oTN09bNepO3Fy2etSduDltl6g7cfPQblF34uZXu0bdiZv/2T3qTtz8K0PQI3EXdww6Q9SduIvKHHUn7mIqRN2Ju4gqQY/Endgx6CpRd+JOqHrUnbgTEfVP4t6coH/nEpsS9WMushlRn+cyGxD0c1xpYaJ+jWstJgq6jetcbQFRzG28xgU/JIq5j3u45BtFIfdxP1edLAq5j7lceIIo5D7ex7VvEoXcx2e4/JOiiMfxeV7hpCjgcazHq5wk5v14JdISN2mJm7TETVriJi1xk5a4SUvcpCVu0hI3SX1//wNfb36+AIiyPQAAAABJRU5ErkJggg=="

 


Thank you for your input.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
nageswaragunupudi
Posts: 10729
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 10 times
Contact:

Re: Save JSON Signature string in Memo for printing

Post by nageswaragunupudi »

Save the value in the memofield, without the starting and ending Quotes.
At the time of printing:

Code: Select all | Expand


cImage  := ( cAlias )->MEMO
cImage  := HB_BASE64DECODE( cImage )
@ r, c PRINT TO oPrn IMAGE cImage ............
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
TimStone
Posts: 2956
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA
Has thanked: 25 times
Been thanked: 2 times
Contact:

Re: Save JSON Signature string in Memo for printing

Post by TimStone »

I'm afraid I need a bit of clarification here.

The value is exactly what the JSON reply provides, including the quotes.

I am able to extract the data with:

Code: Select all | Expand

cSigJPG     := HB_HGET( hChgData, "SignatureData")              // Signature


The extracted data has no quotes ( displayed with MsgInfo ). I am using a data object, so I use:

Code: Select all | Expand

oCreditLog:ccdsig := cSigJPG                        // Signature   Memo Field  


I save the object, and there is no problem. It is in the memo field.

Now I tried the code:

Code: Select all | Expand


oImage := oCreditLog:ccdsig
oSignature := HB_BASE64DECODE( oImage )
oPrn:PrintImage(nRow, nCsp, oSignature, nCsp * 35, nRsp * 3, , , .t. )
 


I get nothing printed.

What am I doing wrong here ?

Thank you.

Tim
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
Posts: 2956
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA
Has thanked: 25 times
Been thanked: 2 times
Contact:

Re: Save JSON Signature string in Memo for printing

Post by TimStone »

Actually please look at my previous post. I am NOW getting an image ( it was pretty poor in the sample I had so I didn't see it ).

I am using the following code:

Code: Select all | Expand


oPrn:PrintImage(nRow, nCsp, oSignature, nCsp * 35, nRsp * 3, , , .t. )
 


What I am finding is that the image is justifying on the RIGHT side of the box ( nCsp*35 ).
Is PrintImage() correct ?
Is there a way to get it to align to the LEFT side ? I want it to print starting at nCsp ( the beginning column ).

Thanks ... Almost there.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
cmsoft
Posts: 1297
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina
Been thanked: 2 times

Re: Save JSON Signature string in Memo for printing

Post by cmsoft »

Tim, you can use the print command with an image

Code: Select all | Expand


@ 1,1 PRINT TO oPrn IMAGE oSignature SIZE 8, 3 CM LASTROW nRow ALIGN "C"
// Align "C","L" or "R"
// nRow Save the value for next printing
 


Code: Select all | Expand


#xcommand @ <nRow>, <nCol> PRINT TO <prn> IMAGE <img> ;
      [SIZE <nWidth> [,<nHeight>] ] ;
      [<unit: PIXEL,MM,CM,INCHES,SCREEN>] ;
      [<lStr: STRETCH>] ;
      [ ALPHALEVEL <nAlpha>] ;
      [<lNoTrn: NOTRANSPARENT>] ;
      [<lGray: GRAY> ] ;
      [ALIGN <aln>] ;
      [URL <cURL> ] ;
      [LASTROW <lrow>] ;
   => ;
      [<lrow> := ] <prn>:PrintImage( <nRow>, <nCol>, <img>, [<nWidth>], [<nHeight>], ;
            [<.lStr.>], [<nAlpha>], [!<.lNoTrn.>], [<.lGray.>], [<(unit)>], [<aln>], [<cURL>] )
User avatar
TimStone
Posts: 2956
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA
Has thanked: 25 times
Been thanked: 2 times
Contact:

Re: Save JSON Signature string in Memo for printing

Post by TimStone »

Thank you. Looking at the code I didn't see the additional parameters.

As you can see, I am using the PRINT command but in the class ... so your example translates to what I was using ... but I didn't have the alignment parameter.

All of my printouts are done with objects/classes using the tPrinter class. I've done it so long I'm pretty used to it.

Now my issue is fully resolved. I appreciate the tip.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Post Reply