【问题标题】:include jquery signature into PDF with FPDF使用 FPDF 将 jquery 签名包含到 PDF 中
【发布时间】:2018-06-07 09:37:05
【问题描述】:

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

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

和FPDF php插件生成pdf

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

使用 FPDF 我可以插入图像,但在将签名导出为 jpeg/png 时遇到问题(我什至不知道是否可行)

我该怎么做

【问题讨论】:

    标签: php jquery pdf fpdf


    【解决方案1】:

    在您在Save/Restore 选项卡中提供指向 (this one) 的链接的页面上,您可以将其保存为 base64 编码图片(jpeg 或 png)。

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

    问题是data:image/png;base64, 包含在编码内容中。这将导致 base64 函数解码时图像数据无效。在解码字符串之前删除函数中的数据,就像这样。

    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是一个保存图片的文件路径。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-26
      • 1970-01-01
      • 2021-09-26
      • 2012-10-23
      • 1970-01-01
      • 1970-01-01
      • 2012-10-29
      • 2012-03-16
      相关资源
      最近更新 更多