Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Signature Capture and Display on report

Questions related to nuBuilder Forte Reports and the Report Builder.
Post Reply
persekor
Posts: 1
Joined: Tue May 03, 2022 8:16 am

Signature Capture and Display on report

Unread post 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
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Signature Capture and Display on report

Unread post 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;

}
Post Reply