1
0
mirror of https://github.com/24eme/signaturepdf.git synced 2023-08-25 09:33:08 +02:00

La largeur du textbox s'adapte automatiquement à la largeur du texte

This commit is contained in:
Vincent LAURENT 2021-11-13 10:46:45 +01:00
parent 13bea28f0e
commit be29f851d5

View File

@ -12,6 +12,8 @@ dataTransfer.items.add(new File([pdfBlob], filename, {
}));
document.getElementById('input_pdf').files = dataTransfer.files;
fabric.Textbox.prototype._wordJoiners = /[]/;
// Loaded via <script> tag, create shortcut to access PDF.js exports.
var pdfjsLib = window['pdfjs-dist/build/pdf'];
@ -605,7 +607,6 @@ loadingTask.promise.then(function(pdf) {
var textbox = new fabric.Textbox('Texte à modifier', {
left: x,
top: y - 20,
width: 300,
fontSize: 20,
fontFamily: 'Monospace'
});
@ -851,6 +852,13 @@ loadingTask.promise.then(function(pdf) {
item.scale = event.target.width * event.target.scaleX / event.target.canvas.width;
storeCollections();
});
canvasEdition.on("text:changed", function(event) {
if (!event.target instanceof fabric.IText) {
return;
}
const textLinesMaxWidth = event.target.textLines.reduce((max, _, i) => Math.max(max, event.target.getLineWidth(i)), 0);
event.target.set({width: textLinesMaxWidth});
});
canvasEditions.push(canvasEdition);
});
}