Hi there!
I’m making a blank app, witch outputs a handcrafted PDF. Is there a way to get or convert the signature field as image? (png)
The actual signature is stored as text in the DB, in a kinda “propietary” format: jsignature base/30.
Thanks!
Hi there!
I’m making a blank app, witch outputs a handcrafted PDF. Is there a way to get or convert the signature field as image? (png)
The actual signature is stored as text in the DB, in a kinda “propietary” format: jsignature base/30.
Thanks!
+1
i need also to use signature fields in control app and use the field in sql statements.
Someone faced the same situation?
Thanks
Was wondering myself if the new signature field would be able to be used in the pdf area. It’s not listed as a field type when creating a pdf in scriptcase.
Finally i’ve got it working!. I’ve created a Blank aplication, which generated the PNG Image from the signature field… I will post the steps later.
With the signature working as image, is easy to embedded it to a PDF
The steps:
Step 1) Create a blank app:
// Route to the library folder, I’made a function for that (is different in development than production)
$rutaLib=variableSistema(‘rutaFirmaLib’);
require_once($rutaLib."jSignature_Tools_Base30.php ");
// external variables: id is the row id to get the correct signature
$id=[id];
sc_sql_injection($id);
$data="";
// Get the signature
$query=“select signatureField from tableWithSignatureField where rowID=’$id’”;
sc_lookup(rs_png, $query);
if (isset({rs_png[0][0]})) // Row found
{
$data = {rs_png[0][0]};
}
// clean the signature
$data = str_replace(‘data:image/jsignature;base30,’, ‘’, $data);
//----------------- Conversion start--------------
$converter = new jSignature_Tools_Base30();
$raw = $converter->Base64ToNative($data);
//Calculate dimensions
$width = 0;
$height = 0;
foreach($raw as $line)
{
if (max($line[‘x’])>$width)$width=max($line[‘x’]);
if (max($line[‘y’])>$height)$height=max($line[‘y’]);
}
// Create an image
$im = imagecreatetruecolor($width+20,$height+20);
// Save transparency for PNG
imagesavealpha($im, true);
// Fill background with transparency
$trans_colour = imagecolorallocatealpha($im, 255, 255, 255, 127);
imagefill($im, 0, 0, $trans_colour);
// Set pen thickness
imagesetthickness($im, 2);
// Set pen color to black
$black = imagecolorallocate($im, 0, 0, 0);
// Loop through array pairs from each signature word
for ($i = 0; $i < count($raw); $i++)
{
// Loop through each pair in a word
for ($j = 0; $j < count($raw[$i][‘x’]); $j++)
{
// Make sure we are not on the last coordinate in the array
if ( ! isset($raw[$i][‘x’][$j]))
break;
if ( ! isset($raw[$i][‘x’][$j+1]))
// Draw the dot for the coordinate
imagesetpixel ( $im, $raw[$i][‘x’][$j], $raw[$i][‘y’][$j], $black);
else
// Draw the line for the coordinate pair
imageline($im, $raw[$i][‘x’][$j], $raw[$i][‘y’][$j], $raw[$i][‘x’][$j+1], $raw[$i][‘y’][$j+1], $black);
}
}
//Create Image, and send it via file download
header(‘Content-Type: image/png’);
imagepng($im);
imagedestroy($im);
//----------------- Conversion end--------------
Step 2) Call the app, using the ID to filter the correct signature. I use plain HTML <img> fields to insert the signature in a PDF
@jomscl Thanks for this code.
I’m trying to use it to display a signature in a pdf document created with tcpdf.
But I by no means manage to send the signature to the tcpdf document created.
I created PHPMethods (instead of blank app) and if I call it in tcpdf named like signature_to_image ()
I see the signature image but not the created pdf document.
I tried the following:
$ html_1 = $ im;
$ pdf-> writeHTMLCell (170, ‘’, 20, 90, $ html_1, 0, 0, 1, true, ‘J’, true);
does not work.
Also:
$ pdf-> Image ($ im, '21 ‘,’ 64 ‘,’ 70 ‘,’ 18 ‘,’ PNG ');
does not work.
Anyone have experience and can help with a tip or code snippet how to use this in combination with tcpdf?
Hello @rik
try in
event / onrecord
a variable with the path of the image:
$image_file = ‘…/_lib/img/logo.jpg’;\
then in the pdf code
$pdf-> Image ($image_file, ‘10’, ‘0’, ‘180’, ‘40’, ‘’, ‘’, ‘’, ‘true’);
it should work
this for a pdf document,
but this can work with a blank application
@nsch2308 Sorry, I do not have a picture in the server folder.
Adding a picture to a pdf document created with a tcpd library is easy and I have no problems with it.
I have a Signature field in the Scriptcase that is written in the database table.
The code above converts this format back to the image. However, he displays this image in a browser. (standalone - picture only)
Now I’m looking for a solution for how to send this image to a pdf document created with tcpdf.
@jomscl listed step 2 as follows:
(I use plain HTML <img> fields to insert the signature in a PDF)
Its OK but i dont know the syntax for it to use in tcpdf.
It may be meant to use a pdf option from Scriptcase. But I do not use this option.
@rik @nsch2308 Did you ever get this to work? I’m having serious trouble even getting the image to show. Attached a screen shot of what I get.
Here’s my code in a blank form:// Route to the library folder, I’made a function for that (is different in development than production)
//$rutaLib=variableSistema(‘rutaFirmaLib’);
require_once(“C:/wamp64/www/Common Files996/prod/third/jquery_plugin/jsignature/jSignature_Tools_Base30.php”);
// external variables: id is the row id to get the correct signature
//$id=[id];
//sc_sql_injection($id);
$data="";
// Get the signature
$query = “SELECT insp_sign”
. " FROM inspections59"
. " (IID = ‘2’)";
sc_lookup(rs_png, $query);
if (isset({rs_png[0][0]})) // Row found
{
$data = {rs_png[0][0]};
}
// clean the signature
$data = str_replace(‘data:image/jsignature;base30,’, ‘’, $data);
//----------------- Conversion start--------------
$converter = new jSignature_Tools_Base30();
$raw = $converter->Base64ToNative($data);
//Calculate dimensions
$width = 0;
$height = 0;
foreach($raw as $line)
{
if (max($line[‘x’])>$width)$width=max($line[‘x’]);
if (max($line[‘y’])>$height)$height=max($line[‘y’]);
}
// Create an image
$im = imagecreatetruecolor($width+20,$height+20);
// Save transparency for PNG
imagesavealpha($im, true);
// Fill background with transparency
$trans_colour = imagecolorallocatealpha($im, 255, 255, 255, 127);
imagefill($im, 0, 0, $trans_colour);
// Set pen thickness
imagesetthickness($im, 2);
// Set pen color to black
$black = imagecolorallocate($im, 0, 0, 0);
// Loop through array pairs from each signature word
for ($i = 0; $i < count($raw); $i++)
{
// Loop through each pair in a word
for ($j = 0; $j < count($raw[$i][‘x’]); $j++)
{
// Make sure we are not on the last coordinate in the array
if ( ! isset($raw[$i][‘x’][$j]))
break;
if ( ! isset($raw[$i][‘x’][$j+1]))
// Draw the dot for the coordinate
imagesetpixel ( $im, $raw[$i][‘x’][$j], $raw[$i][‘y’][$j], $black);
else
// Draw the line for the coordinate pair
imageline($im, $raw[$i][‘x’][$j], $raw[$i][‘y’][$j], $raw[$i][‘x’][$j+1], $raw[$i][‘y’][$j+1], $black);
}
}
//Create Image, and send it via file download
header(‘Content-Type: image/png’);
imagepng($im);
imagedestroy($im);
//----------------- Conversion end--------------
//Step 2) Call the app, using the ID to filter the correct signature. I use plain HTML fields to insert the signature in a PDF
/**
sc_include_lib (“tcpdf”);
$pdf=new TCPDF();
$pdf->setPrintHeader(false); // remove default header/footer
$pdf->setPrintFooter(false);
$pdf->SetMargins(5, 5, 5, true); // set the margins
$pdf->AddPage(‘P’,‘LETTER’);
$pdf->SetFont(‘helvetica’,’’,6);
$pdf->SetTextColor(0,0,0);
//$pdf->SetFillColor(249,249,249);
$pdf->setCellPaddings(1, 1, 1, 1);
$pdf->Image("$data",5, 12.5, 18, 16, ‘’, ‘’, ‘’, true, 300, ‘’, false, false, 1, false, false, false);
$pdf->WriteHTMLCell(200, 200, 5, 20.5, “$data”, 1,0);
$pdf->Output();
With the help of AI I got it working! For those who still question how to do this here’s the fixed code…modify it as needed
// Step 1) Create a blank app:
require_once(“C:/wamp64/www/Common Files996/prod/third/jquery_plugin/jsignature/jSignature_Tools_Base30.php”);
// Database connection and data retrieval
$query = “SELECT insp_sign FROM inspections59 WHERE IID = ‘2’”;
sc_lookup(rs_png, $query);
$data = “”;
if (isset({rs_png[0][0]})) { // Row found
$data = {rs_png[0][0]};
}
// Clean the signature
$data = str_replace(‘data:image/jsignature;base30,’, ‘’, $data);
// Convert signature from Base30
$converter = new jSignature_Tools_Base30();
$raw = $converter->Base64ToNative($data);
// Calculate dimensions
$width = 0;
$height = 0;
foreach ($raw as $line) {
if (max($line[‘x’]) > $width) $width = max($line[‘x’]);
if (max($line[‘y’]) > $height) $height = max($line[‘y’]);
}
// Create an image
$im = imagecreatetruecolor($width + 20, $height + 20);
// Save transparency for PNG
imagesavealpha($im, true);
$trans_colour = imagecolorallocatealpha($im, 255, 255, 255, 127);
imagefill($im, 0, 0, $trans_colour);
imagesetthickness($im, 2);
$black = imagecolorallocate($im, 0, 0, 0);
// Draw the signature on the image
foreach ($raw as $i => $line) {
for ($j = 0; $j < count($line[‘x’]) - 1; $j++) {
imageline($im, $line[‘x’][$j], $line[‘y’][$j], $line[‘x’][$j + 1], $line[‘y’][$j + 1], $black);
}
}
// Save the image as a temporary PNG file
$temp_file = “temp_signature.png”;
imagepng($im, $temp_file);
imagedestroy($im);
// Step 2) Use the saved image in the PDF
sc_include_lib(“tcpdf”);
$pdf = new TCPDF();
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->SetMargins(5, 5, 5, true);
$pdf->AddPage(‘P’, ‘LETTER’);
$pdf->SetFont(‘helvetica’, ‘’, 6);
$pdf->SetTextColor(0, 0, 0);
$pdf->setCellPaddings(1, 1, 1, 1);
$x = 10; // x-coordinate of the image
$y = 200; // y-coordinate of the image
$width = 50; // width of the image
$height = 40; // height of the image
// Draw the image
$pdf->Image($temp_file, $x, $y, $width, $height, ‘’, ‘’, ‘’, true, 300, ‘’, false, false, 1, false, false, false);
// Draw a box around the image
//$pdf->Rect($x, $y, $width, $height, ‘D’);
// Draw a line underneath the image
$pdf->Line($x, $y + $height, $x + $width, $y + $height);
// Insert the signature image into the PDF
//$pdf->Image($temp_file, 10, 230, 50, 40, ‘’, ‘’, ‘’, true, 300, ‘’, false, false, 1, false, false, false);
// Remove the temporary file
unlink($temp_file);
// Output the PDF to screen for testing
$pdf->Output();
//Output the PDF
//$pdf->Output(DIR . ‘/inspections/{establishment}.pdf’, ‘F’);