We get PDF documents that are output by other software, and then we want to add some names and dates to it (which change according to each document). We've got the JavaScript code all worked out, but the problem is that to do this we have to open JavaScript Console, paste the code, and then click the Run button each time we open a new document.
Is there a way to create a button, save the JavaScript to it, and then add it to the Home tab that will run it when clicked?
JavaScript Code on New Documents SOLVED
Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange
-
- Site Admin
- Posts: 7370
- Joined: Wed Mar 25, 2009 10:37 pm
Re: JavaScript Code on New Documents
Hi Ozinfotech,
indeed one can set a "Run JavaScript" action to a button. On the Form Ribbon use the "Button" tool at add a button, with it selected open the Properties Pane (CTRL+`) and add a Mouse Up Action to Run a JavaScript:
That should get you started. Do let me know if you have any questions doing that.
cheers
indeed one can set a "Run JavaScript" action to a button. On the Form Ribbon use the "Button" tool at add a button, with it selected open the Properties Pane (CTRL+`) and add a Mouse Up Action to Run a JavaScript:
That should get you started. Do let me know if you have any questions doing that.
cheers
You do not have the required permissions to view the files attached to this post.
Best regards
Paul O'Rorke
PDF-XChange Support
http://www.pdf-xchange.com
Paul O'Rorke
PDF-XChange Support
http://www.pdf-xchange.com
-
- Site Admin
- Posts: 19913
- Joined: Mon Jan 12, 2009 8:07 am
Re: JavaScript Code on New Documents
Hello ozinfotech,
And if you want to add a button to the toolbars that will perform your JS code - please take a look at this discussion:
viewtopic.php?f=62&t=28855&p=127141
Kind regards,
Stefan
And if you want to add a button to the toolbars that will perform your JS code - please take a look at this discussion:
viewtopic.php?f=62&t=28855&p=127141
Kind regards,
Stefan
-
- Site Admin
- Posts: 7370
- Joined: Wed Mar 25, 2009 10:37 pm
Re: JavaScript Code on New Documents SOLVED
Good Point Stefan,
Ozinfotech, try this:
Save is as a .js file in the folder C:\Program Files\Tracker Software\PDF Editor\JavaScripts - create it if it doesn't exist, the Editor will, on start, look to this folder and add a custom button in a Ribbon called "Add-On Tools", just replace the contents of the function ReversePageOrder() with your JavaScript and label the button as you wish.
This function reverses the page order. I created my own Icon graphic, 32x32 px .png saved to that same JavaScripts folder and referenced in the script. Each press of the button runs the JavaScript. I believe this is the core functionality you are looking for. It looks like this:
I hope that gets you where you want to be. Do not hesitate to ask if you have any questions with any of this.
Ozinfotech, try this:
Code: Select all
// Change file ext. to .js. Then save to C:\Program Files\Tracker Software\PDF Editor\JavaScripts
var Icon = null;
try
{
Icon = util.iconStreamFromImage("/C/Program Files/Tracker Software/PDF Editor/JavaScripts/reverseDirection.png"); // full path should be specified
}
catch (e)
{
}
function ReversePageOrder()
{
for (i = this.numPages - 1; i >= 0; i--) this.movePage(i);
}
app.addToolButton({
cName: "Reverse Page Order",
cLabel: "Reverse Page Order",
oIcon: Icon,
cExec: "ReversePageOrder()",
cTooltext: "Reverse pages",
cEnable: true,
nPos: 0
});
This function reverses the page order. I created my own Icon graphic, 32x32 px .png saved to that same JavaScripts folder and referenced in the script. Each press of the button runs the JavaScript. I believe this is the core functionality you are looking for. It looks like this:
I hope that gets you where you want to be. Do not hesitate to ask if you have any questions with any of this.
You do not have the required permissions to view the files attached to this post.
Best regards
Paul O'Rorke
PDF-XChange Support
http://www.pdf-xchange.com
Paul O'Rorke
PDF-XChange Support
http://www.pdf-xchange.com
-
- User
- Posts: 12
- Joined: Wed Sep 01, 2021 2:58 pm
Re: JavaScript Code on New Documents
Excellent! Thank you very much. 

-
- User
- Posts: 12
- Joined: Wed Sep 01, 2021 2:58 pm
Re: JavaScript Code on New Documents
It works flawlessly. Thank you again!
-
- Site Admin
- Posts: 7370
- Joined: Wed Mar 25, 2009 10:37 pm
JavaScript Code on New Documents
My pleasure.


Best regards
Paul O'Rorke
PDF-XChange Support
http://www.pdf-xchange.com
Paul O'Rorke
PDF-XChange Support
http://www.pdf-xchange.com