Skip to content

Commit

Permalink
added ready option
Browse files Browse the repository at this point in the history
  • Loading branch information
RavishaHesh committed Oct 16, 2020
1 parent 979b9ae commit b29bf32
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)'))

Expand Down
7 changes: 6 additions & 1 deletion pdfannotate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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()
}
});
}

Expand Down
5 changes: 4 additions & 1 deletion script.js
Original file line number Diff line number Diff line change
@@ -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');
}
});

Expand Down

0 comments on commit b29bf32

Please sign in to comment.