I had to create a custom pdf using TCPDF code in a Blank form instead of using the built in Scriptcase pdf builder. I can’t get the Signature field to display the signature, it will only display the Blob data that is stored in the database. Has anyone successfully converted the jsignature:30 blob information to an image when using signatures in a blank report? I’ve looked at other posts from years ago but so far none of the suggested information has helped and all links in older posts are no longer valid.
Thanks!
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’);
You will need to change your database, table, field names etc. If you know how to change directories for the library then do it. I had no success so I used the full info. Change your output directory and file name too. Hope this helps someone who has been looking as long as I have for a solution to this!