1
0
Fork 0
mirror of https://github.com/24eme/signaturepdf synced 2024-06-04 06:52:20 +02:00

Le dessin de la signature passe par le mécanisme de transformation

This commit is contained in:
Vincent LAURENT 2021-09-25 16:38:14 +02:00
parent 4eebe0df75
commit 9ef0c003e8

View file

@ -50,7 +50,7 @@ loadingTask.promise.then(function(pdf) {
document.getElementById('btn_modal_ajouter').addEventListener('click', function() {
if(document.getElementById('nav-draw-tab').classList.contains('active')) {
svgCollections.push(signaturePad.toDataURL("image/svg+xml"));
svgCollections.push(document.getElementById('img-upload').src);
}
if(document.getElementById('nav-type-tab').classList.contains('active')) {
var fontPath = fontCaveat.getPath(document.getElementById('input-text-signature').value, 0, 0, 42);
@ -73,9 +73,36 @@ loadingTask.promise.then(function(pdf) {
document.querySelector('#svg_list label:last-child').click();
});
function dataURLtoBlob(dataurl) {
var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
while(n--){
u8arr[n] = bstr.charCodeAt(n);
}
return new Blob([u8arr], {type:mime});
}
var signaturePad = new SignaturePad(document.getElementById('signature-pad'), {
penColor: 'rgb(0, 0, 0)',
onEnd: function() { document.getElementById('btn_modal_ajouter').focus() }
minWidth: 1.5,
maxWidth: 2.25,
throttle: 0,
onEnd: function() {
const file = new File([dataURLtoBlob(signaturePad.toDataURL("image/svg+xml"))], "draw.svg", {
type: 'image/svg+xml'
});
var data = new FormData();
data.append('file', file);
xhr = new XMLHttpRequest();
xhr.open( 'POST', document.getElementById('form-image-upload').action, true );
xhr.onreadystatechange = function () {
var svgImage = "data:image/svg+xml;base64,"+btoa(this.responseText);
document.getElementById('img-upload').src = svgImage;
document.getElementById('img-upload').classList.remove("d-none");
document.getElementById('btn_modal_ajouter').focus();
};
xhr.send( data );
}
});
document.querySelectorAll('#modalAddSvg .nav-link').forEach(function(item) { item.addEventListener('shown.bs.tab', function (event) {