Exibição do campo Assinatura TCPDF

Olá,

Estou procurando uma solução para imprimir o campo “Assinatura” em um documento * .pdf criado usando a biblioteca tcpdf.
Eu tenho duas assinaturas no formulário, que devo mostrar agora no PDF.
Alguém já foi capaz de fazer isso antes?

Obrigado por ajudar a todos com antecedência.
Igor

Boa tarde.
Conseguiu resolver essa situação?

Resolvi a situação salvando a assinatura no disco como uma imagem usando a biblioteca e imprimindo-a em um documento pdf.

Se a solução combina com você, posso postar o código.

Olá, estou tendo esse problema onde salva o binario base 30, poderia me passar como você conseguiu modificar ele?

Passo 1
Criamos uma biblioteca externa: jSignature_Tools_Base30
e digite o código:

<?php /** @license jSignature v2 SVG export plugin. Copyright (c) 2012 Willow Systems Corp http://willow-systems.com MIT License */ class jSignature_Tools_Base30 { // private $acceptedformat = 'image/jsignature;base30'; private $chunkSeparator = ''; private $charmap = array(); // {'1':'g','2':'h','3':'i','4':'j','5':'k','6':'l','7':'m','8':'n','9':'o','a':'p','b':'q','c':'r','d':'s','e':'t','f':'u','0':'v'} private $charmap_reverse = array(); // will be filled by 'uncompress*" function private $allchars = array(); private $bitness = 0; private $minus = ''; private $plus = ''; function __construct() { global $bitness, $allchars, $charmap, $charmap_reverse, $minus, $plus, $chunkSeparator; $allchars = str_split('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWX'); $bitness = sizeof($allchars) / 2; $minus = 'Z'; $plus = 'Y'; $chunkSeparator = '_'; for($i = $bitness-1; $i > -1; $i--){ $charmap[$allchars[$i]] = $allchars[$i+$bitness]; $charmap_reverse[$allchars[$i+$bitness]] = $allchars[$i]; } } /* Decompresses half of a stroke in a base30-encoded jSignature image. $c = new jSignature_base30(); $t = array(236, 233, 231, 229, 226, 224, 222, 216, 213, 210, 205, 202, 200, 198, 195, 193, 191, 189, 186, 183, 180, 178, 174, 172); $leg = '7UZ32232263353223222333242'; $a = $c->uncompress_stroke_leg($leg); $t == $a */ private function uncompress_stroke_leg($datastring){ global $charmap, $charmap_reverse, $bitness, $minus, $plus; // we convert half-stroke (only 'x' series or only 'y' series of numbers) // datastring like this: // "5agm12100p1235584210m53" // is converted into this: // [517,516,514,513,513,513,514,516,519,524,529,537,541,543,544,544,539,536] // each number in the chain is converted such: // - digit char = start of new whole number. Alpha chars except "p","m" are numbers in hiding. // These consecutive digist expressed as alphas mapped back to digit char. // resurrected number is the diff between this point and prior coord. // - running polaritiy is attached to the number. // - we undiff (signed number + prior coord) the number. // - if char 'm','p', flip running polarity $answer = array(); $chars = str_split( $datastring ); $l = sizeof( $chars ); $ch = ''; $polarity = 1; $partial = array(); $preprewhole = 0; $prewhole = 0; for($i = 0; $i < $l; $i++){ // echo "adding $i of $l to answer\n"; $ch = $chars[$i]; if (array_key_exists($ch, $charmap) || $ch == $minus || $ch == $plus){ // this is new number - start of a new whole number. // before we can deal with it, we need to flush out what we already // parsed out from string, but keep in limbo, waiting for this sign // that prior number is done. // we deal with 3 numbers here: // 1. start of this number - a diff from previous number to // whole, new number, which we cannot do anything with cause // we don't know its ending yet. // 2. number that we now realize have just finished parsing = prewhole // 3. number we keep around that came before prewhole = preprewhole if (sizeof($partial) != 0) { // yep, we have some number parts in there. $prewhole = intval( implode('', $partial), $bitness) * $polarity + $preprewhole; array_push( $answer, $prewhole ); $preprewhole = $prewhole; } if ($ch == $minus){ $polarity = -1; $partial = array(); } else if ($ch == $plus){ $polarity = 1; $partial = array(); } else { // now, let's start collecting parts for the new number: $partial = array($ch); } } else /* alphas replacing digits */ { // more parts for the new number array_push( $partial, $charmap_reverse[$ch]); } } // we always will have something stuck in partial // because we don't have closing delimiter array_push( $answer, intval( implode('',$partial), $bitness ) * $polarity + $preprewhole ); return $answer; } /* $c = new jSignature_base30(); $signature = "3E13Z5Y5_1O24Z66_1O1Z3_3E2Z4"; // This is exactly the same as "native" format within jSignature. $t = array( array( 'x'=>array(100,101,104,99,104) ,'y'=>array(50,52,56,50,44) ) ,array( 'x'=>array(50,51,48) ,'y'=>array(100,102,98) ) ); $a = $c->Base64ToNative($signature); $t == $a */ public function Base64ToNative($datastring){ global $chunkSeparator; $data = array(); $chunks = explode( $chunkSeparator, $datastring ); $l = sizeof($chunks) / 2; for ($i = 0; $i < $l; $i++){ array_push( $data, array( 'x' => $this->uncompress_stroke_leg($chunks[$i*2]) , 'y' => $this->uncompress_stroke_leg($chunks[$i*2+1]) )); } return $data; } } ?>

// *********************************************************************************************************
Passo 2

em seguida, adicione o evento onAfterInsert

{signature_1_pic} = “RP-1-1”; // *** Prefix imena podpisa za sliko in tabelo - Prefix signature names for image and table
{signature_2_pic} = “RP-1-2”; // *** Prefix imena podpisa za sliko in tabelo - Prefix signature names for image and table
{id} = {id};

$signature_name1 = “”.{id}."".""."".{location}."".""."".{signature_1_pic}."".".png"; // *** file name of signature saved on disk ***
$signature_name2 = “”.{id}."".""."".{location}."".""."".{signature_2_pic}."".".png"; // *** file name of signature saved on disk ***

{signature_name1} = $signature_name1;
{signature_name2} = $signature_name2;

$update_table = “UPDATE report_01 SET signature_name1 = ‘$signature_name1’, signature_1 = 1, signature_name2 = ‘$signature_name2’, signature_2 = 1 WHERE id = {id}”;
sc_exec_sql($update_table);

// ****************************************************************************************************************************************************************************

sc_include_library(“prj”, “jSignature_Tools_Base30”, “jSignature_Tools_Base30.php”, true, true);

{signature_1_pic} = “RP-1-1”; // *** Prefix imena podpisa za sliko in tabelo - Prefix signature names for image and table
{signature_2_pic} = “RP-1-2”; // *** Prefix imena podpisa za sliko in tabelo - Prefix signature names for image and table

$signature1 = substr({sc_signature1},5);
$signature2 = substr({sc_signature2},5);
{id} = {id};

$filename1 = “”.{id}."".""."".{location}."".""."".{signature_1_pic}."".".png"; // *** file name of signature saved on disk ***
$filename2 = “”.{id}."".""."".{location}."".""."".{signature_2_pic}."".".png"; // *** file name of signature saved on disk ***

// Save Signature 1 to disk START **********************************************************

function base30_to_jpeg($base30_string, $output_file) {

$data = str_replace('image/jsignature;base30,', '', $base30_string);

$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
$ifp = fopen($output_file, “wb”);
imagepng($im, $output_file);
fclose($ifp);
imagedestroy($im);
return $output_file;
}

$imgStr= $signature1;
base30_to_jpeg($imgStr, $filename1);

// Will copy $filename1 to …/signatures/$filename1
copy($filename1,’…/signatures/’.$filename1);
// Delete file after copy to signature folder
$file_to_delete = $filename1;
unlink($file_to_delete);

/// Save Signature 1 to disk END ************************************************************

/// Save Signature 2 to disk START **********************************************************
function base30_to_jpeg($base30_string, $output_file) {

$data = str_replace('image/jsignature;base30,', '', $base30_string);

$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
$ifp = fopen($output_file, “wb”);
imagepng($im, $output_file);
fclose($ifp);
imagedestroy($im);
return $output_file;
}
$imgStr= $signature2;
base30_to_jpeg($imgStr, $filename2);

// Will copy $filename1 to …/signatures/$filename1
copy($filename2,’…/signatures/’.$filename2);
// Delete file after copy to signature folder
$file_to_delete = $filename2;
unlink($file_to_delete);
/// Save Signature 2 to disk END ************************************************************

// ****************************************************************************************************************************************************************************

sc_redir(grid_report_02.php);

Boa tarde Igor…
Desculpe por não responder e agradecer antes…
Cheguei nessa conclusão também, deu certo…
Mas de deparei com outro problema, uma cliente fez a assinatura pelo Celular… e agora quando visualizamos pelo sistema web ele corta a imagem.
vou até postar no forum e verificar o que podemos fazer.

Não tenho certeza se entendo você.
Esta versão é utilizada pelos meus clientes exclusivamente através do Serviço Móvel.
Eles usam o iPad Air e alguns dispositivos iPad mais recentes.