How do I init XOD in WebViewer? "DisplayModes" is undefined - pdftron

I'm trying to load a XOD document into a PDFTron WebViewer. As far as I can read in the documentation and samples, this should be a simple "plug and play"-operation - it should simply work when you point at a file. Ideally, in my example, the document should be fetched from a service, as so:
fetch('/myservice/GetXOD')
.then(function(data) {
$(function() {
var viewerElement = document.getElementById("viewer");
var myWebViewer = new PDFTron.WebViewer({
initialDoc: data.body
}, viewerElement);
});
});
Unfortunately I get the following error:
Uncaught TypeError: Cannot read property 'DisplayModes' of undefined
The reason I'm doing it in a fetch, is because I'm rendering a Handlebars template, and pass the data to instantiate in a callback. However, I've isolated the code into an otherwise "empty" HTML-document, and in the simplified example below, I'm simply pointing at the XOD provided by PDFTron on page load (no fetch this time).
$(function() {
var viewerElement = document.getElementById("viewer");
var myWebViewer = new PDFTron.WebViewer({
initialDoc: 'GettingStarted.xod' // Using the XOD provided by PDFTron
}, viewerElement);
});
This unfortunately returns a different error (HTTP status 416).
Uncaught Error: Error loading document: Error retrieving file: /doc/WebViewer_Developer_Guide.xod?_=-22,. Received return status 416.
The same error appears when I run the samples from PDFTron on localhost.
I'm at a complete loss of how I should debug this further - all the samples assume everything is working out of the box.
I should note that I can actually get PDFs working just fine on localhost, but not on the server. XODs are problematic both on the server and on localhost.

I'm sorry to hear you are having troubles running our samples.
Your error message says 416 which means "Requested range not satisfiable". Perhaps your development servers do not support byte range requests (https://en.wikipedia.org/wiki/Byte_serving).
Could you try passing an option streaming: true? When streaming is true you're just requesting the entire file up front which shouldn't be a problem for any servers but it is a problem for WebViewer if the file is large because it will need to be completely downloaded and parsed at the start which is slow.

Related

Unable to send request to MongoDB nodeJS ADD through POSTMAN -

The question is pretty much self explanatory. I have created a backend for MongoDB using nodeJS. Here is the link to my entire backend project so you can replicate at your own end -->
https://onedrive.live.com/?cid=90b44987ff0f70ac&id=90B44987FF0F70AC%21157&authkey=!AOG8D2nRT--ga9I
Now, through Postman I am trying to send requests to the add operation to add new player items -
The steps I am following are -->
starting up mongo.exe and running use playerDB
starting up mongod.exe
opening command terminal on my backend project and running nodemon server
sending a POST request to Mongoose db through postman like
localhost:4000/playerDB/add
The error I am receiving is ->
400 Unable to add player object
My sample request body is like so:
{
"player_name":"Didier Drogba",
"player_description":"Brawny, cunning, determined and a heart for attempting the most impossible audacious! The one and only!",
"player_position":"Striker",
"player_age":"42",
"player_club":"Chelsea FC",
"player_":"Hall of Fame",
"player_isactive":"False",
"player_completed":"True"
}
What error did I make? What was the problem? Anythign wrong with the sequence of steps I followed?
Can you point out where I went wrong?
Thanks,
EDIT-->
The new error is:
<body>
<pre>SyntaxError: Unexpected token F in JSON at position 288
<br> at JSON.parse (<anonymous>)
<br> at parse (E:\REACT\MyProj\backend\node_modules\body-parser\lib\types\json.js:89:19)
<br> at E:\REACT\MyProj\backend\node_modules\body-parser\lib\read.js:121:18
<br> at invokeCallback (E:\REACT\MyProj\backend\node_modules\raw-body\index.js:224:16) .....
I have seen your code and there were a couple of changes that were needed.
1) In your player.model.js file, the module.exports should be at the end of the file.
This is because you are exporting the player schema even before it is declared and defined.
2) Two properties in the model: a) player_isactive and b) player_completed are defined as Boolean and you were passing a string from the postman. So you need to send the data as follows:
{
"player_name":"Didier Drogba",
"player_description":"Brawny, cunning, determined and a heart for attempting the most impossible audacious! The one and only!",
"player_position":"Striker",
"player_age":"42",
"player_club":"Chelsea FC",
"player_":"Hall of Fame",
"player_isactive": false,
"player_completed":true
}
Kindly make this changes and your problem is solved.

How can I obtain more detailed error messages from the Nest Firebase API?

Currently I'm connecting to the Nest Thermostat API using Node.js. Currently everything in my application works except for obtaining detailed error messages.
Whenever I want to make a change in the structure I do a _sendUpdate call on the Firebase (_fb) defined as:
FireBaseRef.prototype._sendUpdate = function(path, targetValue, callback) {
log.i('set ' + path + ' (' + targetValue + ')');
this._fb.child(path).set(targetValue, function(error {
log.e(JSON.stringify(error));
});
}
Which uses the Firebase.set() function. Upon error, this callback passes an error object and otherwise null as described here.
As an example error, we try to set the temperature of the Nest thermostat while it is set to Away. According to the Nest API guide, an error message akin to the following should be seen
{
"error": "Cannot change target temperature while structure is Away",
"type": "https://developers.nest.com/documentation/cloud/error-messages#structure-in-away-mode",
"message": "Cannot change target temperature while structure is Away",
"instance": "31441a94-ed26-11e4-90ec-1681e6b88ec1",
}
However, instead I just get a Firebase Warning :
FIREBASE WARNING: set at /devices/thermostats/-GEIJToEG3M9p_jic4J9u7vAgh/target_temperature_c failed: Cannot change target temperature while structure is away
and my logging detects a similar detailless error:
{
"code":"CANNOT CHANGE TARGET TEMPERATURE WHILE STRUCTURE IS AWAY"
}
Can anyone explain how I can attain the more detailed error messages?
Note: I'm using Firebase API 2.4.2 since v3 presented errors with authentication, so I resorted to the version as used in the example code (here)
Try using the Firebase client library 1.1.3 as specified here.
https://developers.nest.com/documentation/cloud/firebase-client-libraries/

how to log js errors at server

I wanted to know does YUI3 provides any way to try and catch errors functionality, where in after the error is captured we can show some customized error alert and simultaneously log the error at server side with the error exceptions and other details.
Also if this functionality is not there in yui3 then which all frameworks do one need to use to do this and which all are compatible with YUI.
I'm not aware of YUI3 providing exactly what you're after out-of-the box.
You can split your question into two parts:
Capturing errors
You either wrap your code with try/catch blocks or use a global error handler. It looks like YUI3 doesn't yet directly handle this (http://yuilibrary.com/projects/yui3/ticket/2528067) but handling it shouldn't be too hard, you'll just have to test for browser differences.
Sending Error data to the server
You ought to be able to use Y.IO to send back the error data to the server. It looks like you get errorMsg, url, lineNumber given to you, so you can just send them back to the server:
YUI().use("io-base",function(Y){
window.onerror = function(errorMsg, url, lineNumber){
Y.io("/errorHandler.php", {
data: {
errorMsg: errorMsg,
url: url,
lineNumber: lineNumber
}
});
alert("Sorry, something bad happened");
};
console.log("handler registered");
//now trigger an error
a.b.c="banana";
});
That seems to work here: http://jsfiddle.net/J83LW/
I'l leave the customized alert to you, I've left an alert here as a basic example of handling this

Node.js : EBADF, Bad file descriptor

If I reload my application (from the browser with the reload button) a lots of times like 50 reload/10 seconds it gives me this error:
events.js:45
throw arguments[1]; // Unhandled 'error' event
^
Error: EBADF, Bad file descriptor
This seems to me like a bandwidth error or something like that, originally I've got the error when I played with the HTML 5 Audio API, and If I loaded the audio file 10-15 times sequentially then I've got the error, but now I've discovered that I get the error without the Audio API too just by reloading the site a lots of times, also Safari gives me the error much faster than Chrome (WTF?)
I'm using Node.js 0.4.8 with express + jade and I'm also connected to a MySQL database with the db-mysql module.
I can't find any articles on the web about this topic what helps, so pleeease let me know what can cause this error because it's really confusing :(
By "reload your application" do you mean refresh your app's home page from a browser, or actually stop and restart the node.js server process? I assume the former, in which case if you can't reliably reproduce this it will be pretty tricky to debug, especially since you don't have a good stack trace to pinpoint the source. But if you use the express.js app.error hook (docs here) you'll want to log the error path from the "Bad file descriptor" error, which should hopefully clue you in to whether this is a temporary file that got deleted or what. In terms of the actual cause, we can only offer guesses since "Bad file descriptor" is a very generic low level error that basically means you are calling an operation on a file descriptor that is no longer in the correct state to handle that operation (like reading a closed file, opening a file that has been deleted, etc).
#CIRK, take a look at this: https://github.com/joyent/node/issues/1189
it's not a node problem, but a system tuning issue.
edit: or maybe it's related to this error in connect 1.4.3:
https://github.com/senchalabs/connect/issues/297
if this is your case, just try to upgrade it
This error may result from using fs to save a file whose name is a number rather than a string. File names must be strings:
Incorrect:
const fileName = 12345;
const fileContent = "The great croissant."
fs.writeFileSync(fileName, fileContent);
Correct:
fs.writeFileSync(`${fileName}`, fileContent);
Also correct:
const fileName = "12345";
fs.writeFileSync(fileName, fileContent);

SWF SecurityError: Error #2000: No active security context

Hi
I have a flash image gallery that worked just fine, until few days a go it stopped loading the images. the debugger throws this error :
SecurityError: Error #2000: No active security context.
can someone explain what can be the cause?
I've run into this problem when working with loading images where the path is located in an external XML file. So... I load the XML get the path from it but then the problem I had was I was loading 30+ images and the error was popping up only 6 times so.. I had no idea which file locations where the bad ones.
If you want flash to out put more info than just :
SecurityError: Error #2000: No active security context.
Add this event listener to your Loader:
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
and finally this function:
protected function ioErrorHandler(e:IOErrorEvent):void{
trace(e.text);
}
With this in place your Security Error will convert to a URL Not Found Error with the file location you supplied. With this information in hand it should be easier for you to debug the problem.
Error #2035: URL Not Found. URL: file:////Volumes/Macintosh%20HD/Users/cleanshooter/Documents/Website%20/here/there/everywhere/30805/filename.jpg
I faced this issue before,the final conclusion was related to incorrect image path or name
Did your images extensions change, possibly from like .jpg to .JPG or something?
Typically this is called if there is a problem with your external media. Here's a workaround for it, but I typically try and solve versus make it go away.
setTimeout( function():void{fileReference.load();}, 1);
Hope this helps.
I ran across this issue and used the above setTimeout example but for a slightly different purpose. I was calling a php script that hit Twitter and got the same security issue in Flash debug player. I just wanted to add my example which builds on the above to show how you can use this "workaround" for URLLoader as well as fileReference.
var myXMLLoader:URLLoader = new URLLoader();
var urlStr:String = "http://www.yourdomain.com/php/twitter.php";
var myVariables:URLVariables = new URLVariables();
myVariables.twitterID = "yourtwitterID";
var myURLRequest:URLRequest = new URLRequest(urlStr)
myURLRequest.data = myVariables;
setTimeout(function():void { myXMLLoader.load( myURLRequest ); }, 1);
myXMLLoader.addEventListener(Event.COMPLETE, onXMLLoadHandler);
You need to handle the error:
loader.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, onHTTPError);
protected function onHTTPError(e:HTTPStatusEvent):void{
trace("HTTPError"+e.status);
}
This way it will handle the error and works fine.
In response to headwinds:
In AS3 you need to import flash.utils.setTimeout. The syntax for setTimeout is setTimeout(A, B, ...rest);
Where B is the function to get called afterwards,
A is the delay in ms (e.g. 1000 for a second)
and C is any number of parameters you need to provide for the function, separated by a comma.
E.g.
import flash.utils.setTimeout;
// package, etc
//main function
setTimeout(respond, 500, true, false);
private function respond(A : Boolean, B : Boolean) : void {
var result : Boolean = A == B;
trace(result);
}

Resources