How to bind the Stored Annotation for pdf - javascript

I am using annotator.js to annotate my PDF documents. I am able to save it to my SQL database and retrieve it. But I am not sure how to Bind back the data on to the specific page. I am using Pure HTML, JQuery for the AnnotatorJS API calls and REST web service to send and receive data in JSON format.
My problem is what are the steps required to use the retrieved data from my SQL database and bind it on to the PDF.
Any suggestions?

I had similar problem before. Try this code. You can change your code accordingly
var subscription= $('#content').annotator();
subscription.data('annotator').plugins['Store'].loadAnnotationsFromSearch().then(function(res) {
subscription.annotator('loadAnnotations', res.rows); res.rows /// in my case
});

Related

How to pass input data dynamically inside Angular Library?

I have to take input from the user and then pass it to API endpoint which is in services section but the services section has to converted into a library. So how can achieve this data transfer without updating the library or putting hardcoded values inside it again and again?
try using type any for the input data in the service library. this is how you will be able to pass any data type the api would receive. Even if the api request data type changes, you don't have to change the service input data type.

Converting an HTML table to JSON to pass to an AJAX call for downloading as a CSV

I am having to write a reporting system in ASP classic.
The people who wrote the wireframe have no concept of performance/speed/how SQL works and so forth so I have lots of fun just getting the data out of the DB.
However they want to have buttons the users can press to "download" the report to a CSV file.
I could submit the form and re-run the SQL (which takes a long time due to the number of reports shown on one page and their format) - and then just send it to the browser as a file.
OR I was thinking of using JS or jQuery etc to take the desired table of contents, somehow convert that to a JSON object, post that to another page using AJAX and then in that other page take the JSON and decode it into a CSV format which can then be delivered to the user as a file.
I just think this JS approach would be quicker and also if I could make it generic so it could take any table with a class on it e.g "report" and convert that into a JSON object that would be used to create a CSV I could easily re-use this code on the hundreds of reports they have made me write.
Does anyone have an JavsaScript code or jQuery that would take a table in any format (it has a thead with column headers, the a tbody with the main contents) and encode it to a JSON or JS object for posting to another page where I could then de-encode it and pipe it out as a CSV file?
Here is a screen shot of one of their reports,
A possible solution to the problem could be to already generate the CSV formatted version of the data for each report when the page that displays the given report is requested. (Database is only queried once per report.) Send the data back in the response in the expected format to display it in the table and save the CSV file to a temporary location on the server.
This way you can place a link near the table 'download CSV' which will point to the already existing file. It will avoid having to query the same data twice for one report OR to having to send the same data to a roundtrip between server and client.
Javascript doesn't provide a way to save text to a file, so you would still have to do that server-side, i.e. by AJAX as you already suggested.
With jQuery you could do something like this (not tested), and send it via an AJAX request.
var headers = [];
$('table.report thead > tr > th').each(function($i, obj) { //or <td> instead of <th>
headers.push($(obj).text());
});
var data = [];
$('table.report tbody > tr').each(function($i, tr) {
var row = [];
$(tr).find('th').each(function($h, td) {
row[headers[$h]] = td.text();
});
data.push(row);
});
var json = JSON.stringify(data);
However I don't think this is the preferable way, because it's still user-input. I could put some random data in a POST and get a CSV in return.
A better way would be to cache your data you already have, and create a CSV file from the cached data when requested.

jQuery Select2 with spring and hibernate

I am using Tag functionality of select 2 in my spring application and hibernate to save it. I am using the AJAX call to save this form.
Till here it is working fine.
My problem is:
How can I populate the data from DB and display it in screen as tag so that user can update it. (this data has id and text)?
How can I save this data in DB using AJAX call. Basic form is saving but for this select2 data I am able to get only keys. I need proper Entity so that I can save/update it directly in DB?
an example will be very much appreciated. right now, I am not putting my code there. Please comment n this post if you want me to post any code.
FYI: I am new in spring and hibernate.

json object directly from my view HTML

i'm using phonegap in order to make an application, then i'm using CodeIgniter as an API.
To get the data, i'm using a simple $.post from jQuery to a REST URL in CodeIgniter.
$.post(DIR+trad+"/format/json", function(data){
traducciones = jQuery.parseJSON(data);
}, json);
Based upon this, i got 2 questions, because i don't know if i should do it in different post methods.
The first question is, how do i get the data in json format?
The second question is, is there any way to call the json object directly from my view (HTML) ? or i need to do it using jquery or javascript?
how do i get the data in json format?
Searching for codeigniter+json gives me Output Class which has this example:
$this->output
->set_content_type('application/json')
->set_output(json_encode(array('foo' => 'bar')));
is there any way to call the json object directly from my view (HTML)?
Generally speaking, if you are generating the JSON yourself and you want to use it in HTML, then you will just skip generating JSON and use the data directly.
Generating JSON from a view only really becomes useful if you want to make the raw data available over a network.
If you want to fetch the data over HTTP for your view, then that is a job for the Model. See How to send a GET request from PHP?. This is useful if you have two different applications. One providing a web service for the data and one providing the user facing application.
If you want to update the page with new data after it has loaded, then this is a good usecase for JSON, but you can only do that with JavaScript (or another client side programming language).
If you want to using JSON as response format, just do like
$.post(url, {
"dataType" : "json",
"success" : function(response) {
// process your response here, it will be treated as JSON object
}
});

Receiving data in javascript from the Plugin using NPN_NewStream

I am trying to send some data as a stream from plug in to javascript. I am using NPN_NewStream for sending the stream from plugin to the browser. I have tried the example mentioned in http://www.terraluna.org/dgp/cvsweb/PluginSDK/Documentation/pi3.htm#npnnewstream successfully. This creates a new stream of HTML text displayed by Netscape in a new window. Now I want to know how I can send some data in the form of xml in a similar way from the plugin to the javascript, receive the data in javascript and do some processing in the javascript with the data sent from the plugin.
I dont' know of a way to do this using NPN_NewStream, and the method for sending HTML to a new window reportedly does not work on all browsers.
However, you can just pass it in a function call as a parameter; make a NPVariant with the text you need and call it into javascript. Alternately have javascript call you and return it from a GetProperty or Invoke call.
FireBreath users do things like this all the time. For more info see http://npapi.com/tutorial3

Categories