I want to convert a images to base64 format for my chrome extension.
CODE:
var img_src = $('#elementId').attr('src');
converImgToBase64(img_src)
function convertImgToBase64(url)
{
var canvas = document.createElement('CANVAS');
ctx = canvas.getContext('2d');
img = document.createElement('img'),
img.src = url;
img.onload = function()
{
canvas.height = img.height;
canvas.width = img.width;
var dataURL = canvas.toDataURL('image/png');
alert(dataURL);
var doc = new jsPDF();
doc.addImage(dataURL, 'JPEG', 15, 40, 180, 160);
doc.output('datauristring');
canvas = null;
};
}
Alert box correctly shows the base64 format of image but PDF IS NOT GENERATING ? How can i generate pdf for my image
So your problem is not having an image in base64, but generating a pdf from it. So please, mind a little more you title next time ;)
By googling all these matters, I found this : http://parall.ax/products/jspdf which, i think, should help you.
As you can see, the homepage example look likes doing all that you need ;)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.