I dont know whether this has been answered before. While using javascript objects like app, Annotation with the ActiveX SDK I get a object does not exist error. In short how do i write javascript code with the API. I apologize if it is repeat question. I cant make any headway writing javascript on any open aspnet PDF webpage?
Would be grateful for your help.
jarathna
app does not exist Javascript error in ActiveX control SDK
Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange
-
- User
- Posts: 10
- Joined: Fri Feb 21, 2014 8:56 am
-
- Site Admin
- Posts: 19868
- Joined: Mon Jan 12, 2009 8:07 am
Re: app does not exist Javascript error in ActiveX control S
Hello jarathna,
I believe you are using this JS API reference. Not all of the methods described there are supported by our Viewer AX SDK.
Most are - but not all. If you describe what you are trying to achieve - we might be able to point you out to an alternative solution.
Regards,
Stefan
I believe you are using this JS API reference. Not all of the methods described there are supported by our Viewer AX SDK.
Most are - but not all. If you describe what you are trying to achieve - we might be able to point you out to an alternative solution.
Regards,
Stefan
-
- User
- Posts: 10
- Joined: Fri Feb 21, 2014 8:56 am
Re: app does not exist Javascript error in ActiveX control S
Thanks Stefan!!!
I do not know how to call the JavaScript APIs on my web page.
My requirement is as follows:
1) I have an aspx web page in which I can load a pdf file.
For this I used
document.all.PDFView.OpenDocument("",0,0,0);
This works. Next
2) In the JavaScript script section of the aspx page I want to find how many Annotations are there for example in the document I opened above
3) Taking the web example provided along with the SDK manual I thought I could code as follows:
document.all.PDFView.RunJavaScript(var annots = this.Doc.getAnnots();,NULL,0,0);
This gives an error that Doc is not an object. The manual gives a number of JavaScript objects specific to PDF like Doc, app, Annotation etc.
4) If I code the normal JavaScript like
document.all.PDFView.RunJavaScript(alert(hello);,NULL,0,0);
This works.
I am in the dark as to how I can use the various JavaScript objects specified in the manual to either call some functions or properties. JavaScript Objects specific to PDF are not visible. What should I do to use them in my web page.
Should I add a js file or something
An example showing how the Annots or Doc or app can be used in the web page will be a great help.
I apologize for being so naïve but I would appreciate your help.
Thanks and regards
jarathna
I do not know how to call the JavaScript APIs on my web page.
My requirement is as follows:
1) I have an aspx web page in which I can load a pdf file.
For this I used
document.all.PDFView.OpenDocument("",0,0,0);
This works. Next
2) In the JavaScript script section of the aspx page I want to find how many Annotations are there for example in the document I opened above
3) Taking the web example provided along with the SDK manual I thought I could code as follows:
document.all.PDFView.RunJavaScript(var annots = this.Doc.getAnnots();,NULL,0,0);
This gives an error that Doc is not an object. The manual gives a number of JavaScript objects specific to PDF like Doc, app, Annotation etc.
4) If I code the normal JavaScript like
document.all.PDFView.RunJavaScript(alert(hello);,NULL,0,0);
This works.
I am in the dark as to how I can use the various JavaScript objects specified in the manual to either call some functions or properties. JavaScript Objects specific to PDF are not visible. What should I do to use them in my web page.
Should I add a js file or something
An example showing how the Annots or Doc or app can be used in the web page will be a great help.
I apologize for being so naïve but I would appreciate your help.
Thanks and regards
jarathna
-
- Site Admin
- Posts: 19868
- Joined: Mon Jan 12, 2009 8:07 am
Re: app does not exist Javascript error in ActiveX control S
Hi jarathna,
The JS you will execute inside the Viewer AX control is slightly different - please refer to the reference file in my above post.
You should be able to use something like
Please also have a look at this post:
https://forum.pdf-xchange.com/ ... 567#p70567
Regards,
Stefan
The JS you will execute inside the Viewer AX control is slightly different - please refer to the reference file in my above post.
You should be able to use something like
Code: Select all
document.all.PDFView.RunJavaScript(var annots = this.getAnnots();,NULL,0,0);
https://forum.pdf-xchange.com/ ... 567#p70567
Regards,
Stefan
-
- User
- Posts: 10
- Joined: Fri Feb 21, 2014 8:56 am
Re: app does not exist Javascript error in ActiveX control S
Thanks for your prompt reply. Am still getting error after I tried in many ways.
Here is the code:
1) function btnOpen_onclick() {
try {
var docID = "";
document.all.PDFView.OpenDocument("", 0, 0, 0);
docID = document.all.PDFView.Property("Documents.Active", 0);
document.all.PDFView.RunJavaScript(var annots = this.getAnnots();,null, 0, 0);
}
catch (err) {
alert(err);
}
This gives a syntax error.
2) function btnOpen_onclick() {
try {
var docID = "";
document.all.PDFView.OpenDocument("", 0, 0, 0);
docID = document.all.PDFView.Property("Documents.Active", 0);
document.all.PDFView.RunJavaScript(var annots = this.getAnnots();, null,0,0)
}
catch (err) {
alert(err);
}
Gives me an error:
Unhandled exception at line 53, column 22 in http://localhost:2513/Default.aspx
0x800a1391 - JavaScript runtime error: 'btnOpen_onclick' is undefined
3) If I remove the semi colon and declare var annots outside:
function btnOpen_onclick() {
try {
var docID = "";
document.all.PDFView.OpenDocument("", 0, 0, 0);
docID = document.all.PDFView.Property("Documents.Active", 0);
var annots = "";
document.all.PDFView.RunJavaScript(annots = this.getAnnots(), null,0,0)
}
catch (err) {
alert(err);
}
I get the following error
TypeError: Object does not support property or method getAnnots().
Please let me know. Seeking your invaluable help
jarathna
Here is the code:
1) function btnOpen_onclick() {
try {
var docID = "";
document.all.PDFView.OpenDocument("", 0, 0, 0);
docID = document.all.PDFView.Property("Documents.Active", 0);
document.all.PDFView.RunJavaScript(var annots = this.getAnnots();,null, 0, 0);
}
catch (err) {
alert(err);
}
This gives a syntax error.
2) function btnOpen_onclick() {
try {
var docID = "";
document.all.PDFView.OpenDocument("", 0, 0, 0);
docID = document.all.PDFView.Property("Documents.Active", 0);
document.all.PDFView.RunJavaScript(var annots = this.getAnnots();, null,0,0)
}
catch (err) {
alert(err);
}
Gives me an error:
Unhandled exception at line 53, column 22 in http://localhost:2513/Default.aspx
0x800a1391 - JavaScript runtime error: 'btnOpen_onclick' is undefined
3) If I remove the semi colon and declare var annots outside:
function btnOpen_onclick() {
try {
var docID = "";
document.all.PDFView.OpenDocument("", 0, 0, 0);
docID = document.all.PDFView.Property("Documents.Active", 0);
var annots = "";
document.all.PDFView.RunJavaScript(annots = this.getAnnots(), null,0,0)
}
catch (err) {
alert(err);
}
I get the following error
TypeError: Object does not support property or method getAnnots().
Please let me know. Seeking your invaluable help
jarathna
-
- Site Admin
- Posts: 19868
- Joined: Mon Jan 12, 2009 8:07 am
Re: app does not exist Javascript error in ActiveX control S
Hi jarathna,
You will need to set this once:
And then your code could look something like:I added "annots.length;" above - so that res has some value - otherwise just using this.getAnnots() does not return any result - and res will remain undefined. The code you will include inside RunJavaScript will be executed by the Viewer AX inside the PDF file and will not be executed on the web page itself - so you need to make sure that the string is properly escaped.
Regards,
Stefan
You will need to set this once:
Code: Select all
pdfViewer.SetProperty("JavaScript.UseExecResult", "true", 0); // call once only, enables JS-output through special "JavaScript.ExecResult" property
Code: Select all
function btnRunJS_Click()
{
try {
PDFView.RunJavaScript("var annots = this.getAnnots(); annots.length;");
res = PDFView.Property("JavaScript.ExecResult", 0);
}
catch (err) {}
}
Regards,
Stefan
-
- User
- Posts: 10
- Joined: Fri Feb 21, 2014 8:56 am
Re: app does not exist Javascript error in ActiveX control S
Thanks a ton Stefan!! That was a million dollar reply!!! It needs a little tweaking to work. Instead of RunJavaScript("var annots = this.getAnnots") it should just be RunJavaScript("this.getAnnots"). I got the hang it.
Ihave one another question. It is regarding DoVerb().
The manual gave the following example
function btnToolbars_onclick() {
document.all.PDFView.DoVerb("", "ExecuteCommand", "ToggleAllBars", 0, 0);
}This a pretty simple example. Two parameter are strings and two numbers.
DoVerb sometimes has an output parameter that is either Variant* or BSTR*. Both of these are non existent in the web page javascript section.
Please tell me how I should execute DoVerb in the above scenarios. An answer to this would given me the info to a great exploration.
Once again appreciate your help.
Thanks and regards
jarathna
Ihave one another question. It is regarding DoVerb().
The manual gave the following example
function btnToolbars_onclick() {
document.all.PDFView.DoVerb("", "ExecuteCommand", "ToggleAllBars", 0, 0);
}This a pretty simple example. Two parameter are strings and two numbers.
DoVerb sometimes has an output parameter that is either Variant* or BSTR*. Both of these are non existent in the web page javascript section.
Please tell me how I should execute DoVerb in the above scenarios. An answer to this would given me the info to a great exploration.
Once again appreciate your help.
Thanks and regards
jarathna
-
- Site Admin
- Posts: 19868
- Joined: Mon Jan 12, 2009 8:07 am
Re: app does not exist Javascript error in ActiveX control S
Hi jarathna,
Glad to help!
JS is indeed limited! DoVerb is the main method, but SetProperty and Property are derivatives from it - so you should be able to obtain values using the .Property ()method, and use DoVerb only when you need to e.g. execute a UI command.
Regards,
Stefan
Glad to help!
JS is indeed limited! DoVerb is the main method, but SetProperty and Property are derivatives from it - so you should be able to obtain values using the .Property ()method, and use DoVerb only when you need to e.g. execute a UI command.
Regards,
Stefan