diff --git a/README.md b/README.md index 0f4a3ab..be60278 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ pdf.savePdf(); // Save PDF with name sample.pdf pdf.serializePdf(); // returns JSON string with canvas data -pdf.loadFromJSON(serializedJSON) // continue edit with saved JSON +pdf.loadFromJSON(serializedJSON) // continue edit with saved JSON. To do this on page load use `ready` option(scripts.js line 5) pdf.setColor(color); // Set color for tools (Example: pdf.setColor(red) , pdf.setColor('#fff'), pdf.setColor('rgba(255,0,0,0.5)')) diff --git a/pdfannotate.js b/pdfannotate.js index 4499453..215dc1f 100644 --- a/pdfannotate.js +++ b/pdfannotate.js @@ -53,7 +53,8 @@ var PDFAnnotate = function(container_id, url, options = {}) { this.initFabric = function () { var inst = this; - $('#' + inst.container_id + ' canvas').each(function (index, el) { + let canvases = $('#' + inst.container_id + ' canvas') + canvases.each(function (index, el) { var background = el.toDataURL("image/png"); var fabricObj = new fabric.Canvas(el.id, { freeDrawingBrush: { @@ -78,6 +79,10 @@ var PDFAnnotate = function(container_id, url, options = {}) { inst.fabricObjectsData[index] = fabricObj.toJSON() fabricObj.off('after:render') }) + + if (index === canvases.length - 1 && typeof options.ready === 'function') { + options.ready() + } }); } diff --git a/script.js b/script.js index b96a779..f0778fb 100644 --- a/script.js +++ b/script.js @@ -1,6 +1,9 @@ var pdf = new PDFAnnotate('pdf-container', 'pdf.pdf', { - onPageUpdated: (page, oldData, newData) => { + onPageUpdated(page, oldData, newData) { console.log(page, oldData, newData); + }, + ready() { + console.log('Plugin initialized successfully'); } });