Page 1 of 1

Signature Capture and Display on report

Posted: Tue Jun 28, 2022 12:45 am
by persekor
Hi,
I am building an App able to collect a signature, store it in the database and display it on a report.
I used a signature pad script (https://github.com/szimek/signature_pad), with a HTML object to capture the signature.
I then used the following code to store the signature as data and store it in the database:
var dataURL = signaturePad.toDataURL();
$('#signature_json').val(dataURL).change();
The format of the data obtained looks like this: "data:image/png;base64,xyzjsksl....."
How do I display a picture saved in the format above, on my pdf report?

Thank you

Re: Signature Capture and Display on report

Posted: Tue Jun 28, 2022 7:02 am
by kev1n
Hi,

I modified nuCreateFile() so that base 64 encoded images can be displayed.
Edit nucommon.php and replace nuCreateFile() with the function below.

Let me know if it works for you.

Code: Select all

function nuCreateFile($j) {

	if ($j == '') return '';

	$id = nuID();

	if (nuStringStartsWith('data:image', $j)) {
		$type = explode('/', mime_content_type($j)) [1];
		$file = sys_get_temp_dir() . "/$id." . '.' . $type;
		list($type, $j) = explode(';', $j);
		list(, $j) = explode(',', $j);
		file_put_contents($file, base64_decode($j));
	}
	else {
		$f = json_decode($j);
		$type = explode('/', $f->type);
		$type = $type[1];
		$file = sys_get_temp_dir() . "/$id." . $type;
		$h = fopen($file, 'w');
		$d = base64_decode($f->file);
		$p = explode(';base64,', $d);
		$p = $p[1];
		$data = base64_decode($p);

		fwrite($h, $data);
		fclose($h);
	}

	return $file;

}