使用 FPDF 将 jquery 签名包含到 PDF 中

include jquery signature into PDF with FPDF

我正在使用这个 jquery 插件来捕捉或绘制签名。

http://keith-wood.name/signature.html

和FPDFphp生成pdf的插件

现在我必须在 pdf 中包含签名...

使用 FPDF 我可以插入图像,但是我无法将签名导出到 jpeg/png(我什至不知道是否可行)

我该怎么做

在 link 给 (this one) 的 Save/Restore 选项卡中,您可以将其保存为 base64 编码图片(jpeg 或 png)。

因此您可以使用它并将 base64 编码的图片保存为文件 here is a solution

The problem is that data:image/png;base64, is included in the encoded contents. This will result in invalid image data when the base64 function decodes it. Remove that data in the function before decoding the string, like so.

function base64_to_jpeg($base64_string, $output_file) {
    // open the output file for writing
    $ifp = fopen( $output_file, 'wb' ); 

    // split the string on commas
    // $data[ 0 ] == "data:image/png;base64"
    // $data[ 1 ] == <actual base64 string>
    $data = explode( ',', $base64_string );

    // we could add validation here with ensuring count( $data ) > 1
    fwrite( $ifp, base64_decode( $data[ 1 ] ) );

    // clean up the file resource
    fclose( $ifp ); 

    return $output_file; 
}

澄清变量 $base64string 是一个字符串,在您的情况下是由插件生成的,$output_file 是保存图片的 filpath。