使用 https://www.npmjs.com/package/jspdf
var image = "" // base 64 image
var url = patientSignature; // url of the image
// Initialize the XMLHttpRequest and wait until file is loaded
var xhr = new XMLHttpRequest();
xhr.onload = function () {
// Create a Uint8Array from ArrayBuffer
var codes = new Uint8Array(xhr.response);
// Get binary string from UTF-16 code units
var bin = String.fromCharCode.apply(null, codes);
// Convert binary to Base64
var b64 ="data:image/jpg;base64,"+ btoa(bin);
// console.log(b64); //-> "R0lGODdhAQABAPAAAP8AAAAAACwAAAAAAQABAAACAkQBADs="
var doc = new jsPDF()
doc.addImage(image, "png", 100, 5, 10, 10);
doc.addImage(bin, "png", 140, 205, 40, 40);
// doc.addImage("data:image/png;base64,"+dataUrl, "JPEG", 100, 5, 10, 10);
var specialElementHandlers = {
'#editor': function(element, renderer){
return true;
}
};
// All units are in the set measurement for the document
// This can be changed to "pt" (points), "mm" (Default), "cm", "in"
doc.fromHTML($('#content').get(0), 15, 10, {
'width': 170,
'elementHandlers': specialElementHandlers
});
doc.save(store_data.patientName+'.pdf');
};
// Send HTTP request and fetch file as ArrayBuffer
xhr.open('GET', url);
xhr.responseType = 'arraybuffer';
xhr.send();
})