How to display a JSON/base64 encoded image in FPDF?

后端 未结 2 799
无人及你
无人及你 2020-12-19 23:42

I\'m storing signatures (using signaturepad in my database Coldfusion/MySQL 5.0.88 and would like to output the signature I\'m taking onto a pdf which I\'m gene

2条回答
  •  -上瘾入骨i
    2020-12-20 00:25

    Originally, I was going to convert to PNG and the more I thought about it, it was more overhead then necessary. After all, Signature Pad give us everything we need to re-draw the signature in FPDF.

    I did the following:

      // decode the signature into an array
        $sig = json_decode($signatureInJSON);
    
        // for each line segment
        foreach ($sig as $line) {
            $lx = $line->lx;
            $ly = $line->ly;
            $mx = $line->mx;
            $my = $line->my;
            // draw the line
            $pdf->Line($lx, $ly, $mx, $my);
        }
    

    Obviously, I also added some functions to scale the signature and offset it to where I wanted in the PDF.

    Hope that helps someone else.

提交回复
热议问题