How can I create a button to start a java script?

Forum for the PDF-XChange Editor - Free and Licensed Versions

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Sean - Tracker, Paul - Tracker Supp, Chris - Tracker Supp, Tracker Supp-Stefan, Ivan - Tracker Software

Post Reply
apee
User
Posts: 5
Joined: Tue Feb 28, 2017 6:20 pm

How can I create a button to start a java script?

Post by apee » Tue Feb 28, 2017 6:30 pm

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

User avatar
Patrick-Tracker Supp
Site Admin
Posts: 1668
Joined: Thu Mar 27, 2014 6:14 pm
Location: Vancouver Island
Contact:

Re: How can I create a button to start a java script?

Post by Patrick-Tracker Supp » Tue Feb 28, 2017 6:35 pm

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!
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

Willy Van Nuffel
User
Posts: 1400
Joined: Wed Jan 18, 2006 12:10 pm

Re: How can I create a button to start a java script?

Post by Willy Van Nuffel » Tue Feb 28, 2017 6:50 pm

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.
Attachments
ReversePageOrder.zip
(305 Bytes) Downloaded 51 times

apee
User
Posts: 5
Joined: Tue Feb 28, 2017 6:20 pm

Re: How can I create a button to start a java script?

Post by apee » Tue Feb 28, 2017 7:06 pm

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

User avatar
Patrick-Tracker Supp
Site Admin
Posts: 1668
Joined: Thu Mar 27, 2014 6:14 pm
Location: Vancouver Island
Contact:

Re: How can I create a button to start a java script?

Post by Patrick-Tracker Supp » Tue Feb 28, 2017 7:10 pm

Hi Willy,

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

Willy Van Nuffel
User
Posts: 1400
Joined: Wed Jan 18, 2006 12:10 pm

Re: How can I create a button to start a java script?

Post by Willy Van Nuffel » Tue Feb 28, 2017 7:17 pm

It was Will - Tracker Support who made us aware of this ...
http://www.tracker-software.com/forum3/ ... pt#p110263

So, he deserves an award too!

:-)

apee
User
Posts: 5
Joined: Tue Feb 28, 2017 6:20 pm

Re: How can I create a button to start a java script?

Post by apee » Tue Feb 28, 2017 8:33 pm

Awards for all of you!

I am very pleased to see so many helpful people here!

User avatar
Patrick-Tracker Supp
Site Admin
Posts: 1668
Joined: Thu Mar 27, 2014 6:14 pm
Location: Vancouver Island
Contact:

Re: How can I create a button to start a java script?

Post by Patrick-Tracker Supp » Tue Feb 28, 2017 8:39 pm

:D
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

User avatar
yogi108
User
Posts: 74
Joined: Thu Mar 09, 2017 9:13 am
Location: Austria, Theiß
Contact:

Re: How can I create a button to start a java script?

Post by yogi108 » Wed Mar 29, 2017 10:35 am

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 ....

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

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 13662
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: How can I create a button to start a java script?

Post by Tracker Supp-Stefan » Wed Mar 29, 2017 11:03 am

Thanks for this Yogi,

It is indeed a cool feature - tried it on a 750 page document - looked lovely :)

Cheers,
Stefan

Karyudo
User
Posts: 8
Joined: Sun Oct 13, 2019 9:48 pm

Re: How can I create a button to start a java script?

Post by Karyudo » Fri Oct 18, 2019 3:13 am

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...?

User avatar
Radi - Tracker Supp
Site Admin
Posts: 400
Joined: Tue Mar 03, 2015 12:46 pm

Re: How can I create a button to start a java script?

Post by Radi - Tracker Supp » Fri Oct 18, 2019 6:10 am

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

Post Reply