How can I create a button to start a java script?
Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan
How can I create a button to start a java script?
Hello,
I have found on this site a wonderful java script which reverses the order of the pages of a document:
for (i = this.numPages - 1; i >= 0; i--) this.movePage(i);
Can anyone give me a hint how to create a button to start this script?
Thank you and best regards,
Apee
I have found on this site a wonderful java script which reverses the order of the pages of a document:
for (i = this.numPages - 1; i >= 0; i--) this.movePage(i);
Can anyone give me a hint how to create a button to start this script?
Thank you and best regards,
Apee
- Patrick-Tracker Supp
- Site Admin
- Posts: 1645
- Joined: Thu Mar 27, 2014 6:14 pm
- Location: Vancouver Island
- Contact:
Re: How can I create a button to start a java script?
Hello Aapee,
Thanks for the post and welcome to our forums. Do you mean a toolbar button, or a button on the page of a PDF?
Thanks!
Thanks for the post and welcome to our forums. Do you mean a toolbar button, or a button on the page of a PDF?
Thanks!
If posting files to this forum, you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded.
Thank you.
Cheers,
Patrick Charest
Tracker Support North America
Thank you.
Cheers,
Patrick Charest
Tracker Support North America
-
- User
- Posts: 2349
- Joined: Wed Jan 18, 2006 12:10 pm
Re: How can I create a button to start a java script?
If it goes about adding a button via the automatically generated "Add-on Tools" toolbar, then there was recently a very useful solution. You just have to incorporate the javascript in a text file with *.js extension and put this file in the JavaScripts folder of your PDF-XChange Editor installation.
Something like this:
C:\Program Files\Tracker Software\PDF Editor\JavaScripts\ReversePageOrder.js
The content of the file might be something like this (sample file in attachment):
function ReversePageOrder()
{
for (i = this.numPages - 1; i >= 0; i--) this.movePage(i);
}
app.addToolButton({
cName: "Reverse Page Order",
cExec: "ReversePageOrder()",
cTooltext: "Reverse pages",
cEnable: true,
nPos: 0
});
Best regards.
Something like this:
C:\Program Files\Tracker Software\PDF Editor\JavaScripts\ReversePageOrder.js
The content of the file might be something like this (sample file in attachment):
function ReversePageOrder()
{
for (i = this.numPages - 1; i >= 0; i--) this.movePage(i);
}
app.addToolButton({
cName: "Reverse Page Order",
cExec: "ReversePageOrder()",
cTooltext: "Reverse pages",
cEnable: true,
nPos: 0
});
Best regards.
- Attachments
-
- ReversePageOrder.zip
- (305 Bytes) Downloaded 170 times
Re: How can I create a button to start a java script?
Hello Patrick (thank you for welcoming me) and hello Willy,
Wow, it works! I am absolutely delighted, that is exactly what I had hoped. Thank you for completed the script for me!
Best regards
Apee
Wow, it works! I am absolutely delighted, that is exactly what I had hoped. Thank you for completed the script for me!
Best regards
Apee
- Patrick-Tracker Supp
- Site Admin
- Posts: 1645
- Joined: Thu Mar 27, 2014 6:14 pm
- Location: Vancouver Island
- Contact:
Re: How can I create a button to start a java script?
Hi Willy,
You deserve an award for that one! It works absolutely perfectly
Take care!
You deserve an award for that one! It works absolutely perfectly
Take care!
If posting files to this forum, you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded.
Thank you.
Cheers,
Patrick Charest
Tracker Support North America
Thank you.
Cheers,
Patrick Charest
Tracker Support North America
-
- User
- Posts: 2349
- Joined: Wed Jan 18, 2006 12:10 pm
Re: How can I create a button to start a java script?
It was Will - Tracker Support who made us aware of this ...
https://forum.pdf-xchange.com/ ... pt#p110263
So, he deserves an award too!
https://forum.pdf-xchange.com/ ... pt#p110263
So, he deserves an award too!
Re: How can I create a button to start a java script?
Awards for all of you!
I am very pleased to see so many helpful people here!
I am very pleased to see so many helpful people here!
- Patrick-Tracker Supp
- Site Admin
- Posts: 1645
- Joined: Thu Mar 27, 2014 6:14 pm
- Location: Vancouver Island
- Contact:
Re: How can I create a button to start a java script?
If posting files to this forum, you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded.
Thank you.
Cheers,
Patrick Charest
Tracker Support North America
Thank you.
Cheers,
Patrick Charest
Tracker Support North America
Re: How can I create a button to start a java script?
Hi there,
Just saw the thermometer object, tried it, here is the result for the sorting function-
good idea to see something on the screen even just sorting 10 pages ....
Just saw the thermometer object, tried it, here is the result for the sorting function-
good idea to see something on the screen even just sorting 10 pages ....
Code: Select all
function ReversePageOrder()
{
var box=app.alert("Change sortorder?",2,2,"reverse page order");
if(box==4){ // yes
var t = app.thermometer; // acquire a thermometer object
t.duration = this.numPages;
t.begin();
var i1=0;
for (i = this.numPages - 1; i >= 0; i--)
{
i1++;
t.text = "Page " + (i1);
t.value = i1;
this.movePage(i);
if (t.cancelled) break;
}
t.end();
}
else if(box==false){
app.alert("Exit");
}
}
"You cannot know the meaning of your life until you are connected to the power that created you.”
Shri Mataji Nirmala Devi, founder of Sahaja Yoga
Shri Mataji Nirmala Devi, founder of Sahaja Yoga
- Tracker Supp-Stefan
- Site Admin
- Posts: 17824
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
- Contact:
Re: How can I create a button to start a java script?
Thanks for this Yogi,
It is indeed a cool feature - tried it on a 750 page document - looked lovely
Cheers,
Stefan
It is indeed a cool feature - tried it on a 750 page document - looked lovely
Cheers,
Stefan
Re: How can I create a button to start a java script?
Is there a video or page that explains how to get ReversePageOrder working? Because there's not enough information in this thread.
I don't want to make this my life-long pursuit; I just want the feature to work. Every second I spend in forums reading half-explained hacks annoys me more. Especially when I follow directions pretty exactly, and don't get the results that everyone else raves about.
Ideally, I wouldn't have to screw around with JavaScript at all, and a ReversePageOrder button would just exist in the base software. But if I'm here already, I guess that's not going to happen.
Second best would be complete explanations that don't assume ANYTHING, and step a casual user through the setup. A little help, someone...?
I don't want to make this my life-long pursuit; I just want the feature to work. Every second I spend in forums reading half-explained hacks annoys me more. Especially when I follow directions pretty exactly, and don't get the results that everyone else raves about.
Ideally, I wouldn't have to screw around with JavaScript at all, and a ReversePageOrder button would just exist in the base software. But if I'm here already, I guess that's not going to happen.
Second best would be complete explanations that don't assume ANYTHING, and step a casual user through the setup. A little help, someone...?
- Radi - Tracker Supp
- Site Admin
- Posts: 598
- Joined: Tue Mar 03, 2015 12:46 pm
Re: How can I create a button to start a java script?
Hi Karyudo,
Please check my answer in your dedicated topic about this Javascript button:
viewtopic.php?f=7&t=33303&p=137305#p137305
Regards,
Radi
Please check my answer in your dedicated topic about this Javascript button:
viewtopic.php?f=7&t=33303&p=137305#p137305
Regards,
Radi
Re: How can I create a button to start a java script?
Hello Yogi and @all,
Should this work as described here:
https://forum.pdf-xchange.com/viewtopic.php?p=137305#p137305
With this JavaScript, no button appears for me in PDF-XChange Editor. Am I doing something wrong?
Best regards
David
Thanks for this code.yogi108 wrote: ↑Wed Mar 29, 2017 10:35 am Just saw the thermometer object, tried it, here is the result for the sorting function-
good idea to see something on the screen even just sorting 10 pages ....
Code: Select all
function ReversePageOrder() { var box=app.alert("Change sortorder?",2,2,"reverse page order"); if(box==4){ // yes var t = app.thermometer; // acquire a thermometer object t.duration = this.numPages; t.begin(); var i1=0; for (i = this.numPages - 1; i >= 0; i--) { i1++; t.text = "Page " + (i1); t.value = i1; this.movePage(i); if (t.cancelled) break; } t.end(); } else if(box==false){ app.alert("Exit"); } }
Should this work as described here:
https://forum.pdf-xchange.com/viewtopic.php?p=137305#p137305
With this JavaScript, no button appears for me in PDF-XChange Editor. Am I doing something wrong?
Best regards
David
David.P
PDF-XChange Pro
PDF-XChange Pro
- TrackerSupp-Daniel
- Site Admin
- Posts: 8440
- Joined: Wed Jan 03, 2018 6:52 pm
Re: How can I create a button to start a java script?
Hello, David.P
This code does not include and directions to create a JS button, so it would simply try to run once and then stop. To add a JS button to the UI, you need to structure the Button logic into the JS you are writing.
Here is some sample code for a re-order pages tool, with button logic included:
Kind regards,
This code does not include and directions to create a JS button, so it would simply try to run once and then stop. To add a JS button to the UI, you need to structure the Button logic into the JS you are writing.
Here is some sample code for a re-order pages tool, with button logic included:
Code: Select all
// Change file ext. to .js. Then save to C:\Program Files\Tracker Software\PDF Editor\JavaScripts
function ReorderPagesA1B1()
{
//Reorder Pages A1, B1, A2, B2, A3, B3...
for (i = 0; i < ((this.numPages - 1)/2); i++)
{
this.movePage(Math.ceil(this.numPages/2)+i,2*i);
}
}
app.addToolButton({
cName: "Re-order Pages",
cLabel: "Re-Order Pages",
cExec: "ReorderPagesA1B1()",
cTooltext: "Reorder Pages A1, B1, A2, B2, A3, B3",
cEnable: true,
nPos: 0
});
Dan McIntyre - Support Technician
Tracker Software Products (Canada) LTD
+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Tracker Software Products (Canada) LTD
+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Re: How can I create a button to start a java script?
Hello Daniel,
thanks very much, that works now.
However, I thought Yogi's code would produce a prompt and something like a progress bar.
This no longer seems to be included in your code, correct?
thanks very much, that works now.
However, I thought Yogi's code would produce a prompt and something like a progress bar.
This no longer seems to be included in your code, correct?
David.P
PDF-XChange Pro
PDF-XChange Pro
- TrackerSupp-Daniel
- Site Admin
- Posts: 8440
- Joined: Wed Jan 03, 2018 6:52 pm
Re: How can I create a button to start a java script?
Hello, David.P
My code example is not adapted to include anything from this thread, I was sharing the button code sepcifically, the re-order pages section was an unrelated bonus shared for posterity.
If you wish for a progress bar to appear however, that woudl also need to be coded. Nothing performed with JS will show any dialogues by default, all messages, buttons, date selection fields, and error messages need to be hand coded into the JS itself in order to be displayed.
Kind regards,
My code example is not adapted to include anything from this thread, I was sharing the button code sepcifically, the re-order pages section was an unrelated bonus shared for posterity.
If you wish for a progress bar to appear however, that woudl also need to be coded. Nothing performed with JS will show any dialogues by default, all messages, buttons, date selection fields, and error messages need to be hand coded into the JS itself in order to be displayed.
Kind regards,
Dan McIntyre - Support Technician
Tracker Software Products (Canada) LTD
+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Tracker Software Products (Canada) LTD
+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Re: How can I create a button to start a java script?
Thank you Daniel,
now I get how to do it.
For once, I have extended Yogi's example with the code block "app.addToolButton({..." from your code. This way, Yogi's code also appears as a button in PDF-XChange Editor.
Yogi's code also indeed creates a prompt and a progress bar.
However, your code is easily a hundred times faster in execution than Yogi's. I don't know if this is due to the algorithm or due to the implementation of the progress bar.
Anyway, the issue is resolved from my side.
Thanks again
David
now I get how to do it.
For once, I have extended Yogi's example with the code block "app.addToolButton({..." from your code. This way, Yogi's code also appears as a button in PDF-XChange Editor.
Yogi's code also indeed creates a prompt and a progress bar.
However, your code is easily a hundred times faster in execution than Yogi's. I don't know if this is due to the algorithm or due to the implementation of the progress bar.
Anyway, the issue is resolved from my side.
Thanks again
David
David.P
PDF-XChange Pro
PDF-XChange Pro
- TrackerSupp-Daniel
- Site Admin
- Posts: 8440
- Joined: Wed Jan 03, 2018 6:52 pm
How can I create a button to start a java script?
Dan McIntyre - Support Technician
Tracker Software Products (Canada) LTD
+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Tracker Software Products (Canada) LTD
+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com