include jquery signature into PDF with FPDF
include jquery signature into PDF with FPDF
I'm using this jquery plugin to capture or draw a signature.
http://keith-wood.name/signature.html
And FPDF php plugin to generate pdf
Now I must include signature into pdf...
With FPDF I can insert an image, but I have problem exporting signature to jpeg/png (I don't even know if is possibile)
How I can do this
1 Answer
1
On the page you gave link to (this one) in Save/Restore
tab you have possibility to save it as a base64 encoded picture (jpeg or png).
Save/Restore
So you can use that and to save base64 encoded picture as a file 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.
data:image/png;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;
}
To clarify variable $base64string
is a string that in your case is generated by plugin, and $output_file
is a filpath where to save the picture.
$base64string
$output_file
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.