Javascript SOLVED
Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan
Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.
When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.
When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Javascript
We are replacing PDFXChange viewer by PDF-XChange Editor and I am trying to run the following javascript with IPXC_Action_JavaScript.Script(String ppScript)
String ppScript = " ";for (var key in this.viewState) {result = result + key + "=" + this.viewState[key]+ " "; };result;
With PDFXChange viewer I run the javascript with the following code:
getAutomation().invoke(getId(TrackerConstants.RUNJAVASCRIPT), new Variant[] { new Variant(script), res, new Variant(0), new Variant() }, new int[] { 0, 1, 2, 3 });
String lastError = getAutomation().getLastError();
result = res.getString();
As a result I get
String result = "pageViewLayoutMode=1 pageViewZoom=100 pageViewZoomType=0 pageViewRow=0 pageViewX=0 pageViewY=0 pageViewBX=-5 pageViewBY=-5 pageViewPageNum=0"
How do I get the same Result with PDF-XChange Editor?
This javascript is just an example and I know that there might be other funktions to get this informations.
I just need to know the general call for a javascript an how to retrieve the result.
String ppScript = " ";for (var key in this.viewState) {result = result + key + "=" + this.viewState[key]+ " "; };result;
With PDFXChange viewer I run the javascript with the following code:
getAutomation().invoke(getId(TrackerConstants.RUNJAVASCRIPT), new Variant[] { new Variant(script), res, new Variant(0), new Variant() }, new int[] { 0, 1, 2, 3 });
String lastError = getAutomation().getLastError();
result = res.getString();
As a result I get
String result = "pageViewLayoutMode=1 pageViewZoom=100 pageViewZoomType=0 pageViewRow=0 pageViewX=0 pageViewY=0 pageViewBX=-5 pageViewBY=-5 pageViewPageNum=0"
How do I get the same Result with PDF-XChange Editor?
This javascript is just an example and I know that there might be other funktions to get this informations.
I just need to know the general call for a javascript an how to retrieve the result.
-
- User
- Posts: 5522
- Joined: Fri Nov 21, 2014 8:27 am
- Contact:
Re: Javascript
Hello AteBe,
This method should be used to execute the JS:
https://sdkhelp.pdf-xchange.com/vi ... _ExecuteJS
Cheers,
Alex
This method should be used to execute the JS:
https://sdkhelp.pdf-xchange.com/vi ... _ExecuteJS
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Re: Javascript
Hello Alex,
thanks for the information.
Unfortunately when I execute my script with the function ExecuteJs, result returns a pointer, but result.Value() is always null.
If I execute the same script in the JavaScript console of the editor, I get a result.
Can you tell me, what am I doing wrong?
AteBe
thanks for the information.
Unfortunately when I execute my script with the function ExecuteJs, result returns a pointer, but result.Value() is always null.
Code: Select all
public IString runJavaScript(String script)
{
IString result = getInst().CreateString("");
try {
IPXV_Document doc = getInst().ActiveDoc();
Pointer p = iControlSite.getPointerToUnknown();
IPXV_Inst sc = new IPXV_Inst(p);
sc.ExecuteJS(doc, script, PXV_ActionTriggerClass.PAEC_External, PXV_ActionTriggerSubclass.PAESC_Exec, null,
result);
} catch (Exception e) {
e.getMessage();
}
return result;
}
Can you tell me, what am I doing wrong?
AteBe
-
- User
- Posts: 5522
- Joined: Fri Nov 21, 2014 8:27 am
- Contact:
Re: Javascript
Hello AteBe,
Well, if you could specify a script (with document if needed) to recreate this behavior then we'll take a look at it.
Cheers,
Alex
Well, if you could specify a script (with document if needed) to recreate this behavior then we'll take a look at it.
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Re: Javascript
Hallo Alex,
the script is the same I posted before and it should work with any pdf .
" ";for (var key in this.viewState) {result = result + key + "=" + this.viewState[key]+ " "; };result;
if I use it in the Editor I get the following result.
[img]JsEditor.JPG[/img]
AteBe
the script is the same I posted before and it should work with any pdf .
" ";for (var key in this.viewState) {result = result + key + "=" + this.viewState[key]+ " "; };result;
if I use it in the Editor I get the following result.
[img]JsEditor.JPG[/img]
AteBe
-
- User
- Posts: 5522
- Joined: Fri Nov 21, 2014 8:27 am
- Contact:
Re: Javascript
Hello AteBe,
Just tried your script on the FullDemo application's JavaScript tab - everything worked OK. Here's the code used in it:
Cheers,
Alex
Just tried your script on the FullDemo application's JavaScript tab - everything worked OK. Here's the code used in it:
Code: Select all
private void btnRunJS_Click(object sender, EventArgs e)
{
PDFXEdit.IString res = pdfCtl.Inst.CreateString();
try
{
pdfCtl.Inst.ExecuteJS(pdfCtl.Doc, tInputJS.Text, PDFXEdit.PXV_ActionTriggerClass.PAEC_External, PDFXEdit.PXV_ActionTriggerSubclass.PAESC_Exec, null, res);
}
catch { }
tOutputJS.Text = res.Value;
}
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Re: Javascript
Hallo Alex,
unfortunately, the Java code I derived from your C# code does not work for me.
The parameter res returns a value. But with the funktion res.Value() I get null.
The script I am using is still the same:
" ";for (var key in this.viewState) {result = result + key + "=" + this.viewState[key]+ " "; };result;
Is there a difference between java and c # that I have overlooked?
AteBe
unfortunately, the Java code I derived from your C# code does not work for me.
Code: Select all
private OleControlSiteEx iControlSite = new OleControlSiteEx(frame, SWT.NONE, "PDFXEdit.PXV_Control.1");
iControlSite.doVerb(OLE.OLEIVERB_SHOW);
iControlSite.doVerb(OLE.OLEIVERB_UIACTIVATE);
private IPXV_Control iCtrl = new IPXV_Control(iControlSite.getPointerToUnknown());
private IPXV_Inst iInst = iCtrl.Inst();
public String runJavaScript(String script)
{
IString res = iInst.CreateString(null);
try
{
IPXV_Document doc = iInst.ActiveDoc();
Pointer p = iControlSite.getPointerToUnknown();
IPXV_Inst sc = new IPXV_Inst(p);
sc.ExecuteJS(doc, script, PXV_ActionTriggerClass.PAEC_External, PXV_ActionTriggerSubclass.PAESC_Exec, null, res);
}
catch (Exception e)
{
e.getMessage();
}
return res.Value();
}
The script I am using is still the same:
" ";for (var key in this.viewState) {result = result + key + "=" + this.viewState[key]+ " "; };result;
Is there a difference between java and c # that I have overlooked?
AteBe
-
- User
- Posts: 5522
- Joined: Fri Nov 21, 2014 8:27 am
- Contact:
Re: Javascript
Hello AteBe,
Does it work in the FullDemo application on your machine?
Cheers,
Alex
Does it work in the FullDemo application on your machine?
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Re: Javascript
Hallo Alex,
because we do not use C# I just downloaded the code files.
Therefore I have no running FullDemo application .
AteBe
because we do not use C# I just downloaded the code files.
Therefore I have no running FullDemo application .
AteBe
Re: Javascript
Hallo Alex,
I found the mistake in my code.
Instead of using the current IPXV_Inst instance, I have created a new (empty) instance and therefore I always got zero.
Now the JavaScript returns the correct result.
Thanks again for the support.
AteBe
I found the mistake in my code.
Instead of using the current IPXV_Inst instance, I have created a new (empty) instance and therefore I always got zero.
Now the JavaScript returns the correct result.
Thanks again for the support.
AteBe
-
- User
- Posts: 5522
- Joined: Fri Nov 21, 2014 8:27 am
- Contact:
Re: Javascript SOLVED
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ