Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to load saved annotations? #18

Closed
abhimanusharma opened this issue Oct 16, 2020 · 6 comments
Closed

Is it possible to load saved annotations? #18

abhimanusharma opened this issue Oct 16, 2020 · 6 comments

Comments

@abhimanusharma
Copy link

Hi,

I saw a loadFromJSON already exists but I tried to use it and it won't work. I am getting configurations from serializePdf function and tried to load it into the loadFromJson before inst.initFabric() call.

I wanted to load prev state of of annotation last added by user, which can be editable and new annotation can be added as permission given to the user.

@RavishaHesh
Copy link
Owner

Hey! There was an issue in that functions which made it impossible load JSON at page load. I've always checked that function with AJAX. That's why I haven't found that issue until now.
I have added ready option which get called after the plugin initialization(PDFJs workers takes little bit of time to render the pages). You use that function to load JSON on page load like this

var pdf = new PDFAnnotate('pdf-container', 'pdf.pdf', {
    ready() {
        pdf.loadFromJSON(<json>)
    }
});

@abhimanusharma
Copy link
Author

Is this function on master branch or develop branch?

Actually i have removed jQuery completely and converted whole functionality with vanilla Javascript.

@RavishaHesh
Copy link
Owner

it's on master

@abhimanusharma
Copy link
Author

@RavishaHesh Please check the option again,

var pdf = new PDFAnnotate('pdf-container', 'pdf.pdf', {
    ready() {
        pdf.loadFromJSON(<json>)
    }
});

In above example, pdf.loadFromJSON(<json>) pdf is not yet defined.

I have tried this, My main file

this.pdf = 
	new PDFAnnotate('pdf-container', this.url, docConf, {
		onPageUpdated: (page, oldData, newData) => {
			console.log(page, oldData, newData);
		},
		ready() {
			this.pdf.loadFromJSON(docConf);
		}
	});

ERROR: docConf is not defined

Then,

ready(docConf) {
	this.pdf.loadFromJSON(docConf);
}

ERROR: app.js:21113 Uncaught (in promise) TypeError: Cannot read property 'loadFromJSON' of undefined

annotatepdf.js file is

if (index === canvasArr.length - 1 && typeof options.ready === 'function') {
	options.ready()
}

Tried to change

if (index === canvasArr.length - 1 && typeof options.ready === 'function') {
	options.ready(inst.docConf)
}

Even than its not working. Can you please show a working example that loads json from script.js into pdf on load?

@RavishaHesh
Copy link
Owner

Actually above error occurs because you have binding the pdf variable to the current context. The context inside the callback function is different to the script's context
If you really want to bind your variable to the context you can use something like

var pdf = new PDFAnnotate("pdf-container", "pdf.pdf", {
  onPageUpdated(page, oldData, newData) {
    console.log(page, oldData, newData);
  },
  ready: function () {
    console.log(this);
  }.bind(this),
});

@RavishaHesh
Copy link
Owner

Hope I have answered your issue. Feel free to re-open if you need further clarifications

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants