Using JavaScript to automate tasks
Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan
-
- User
- Posts: 6
- Joined: Wed Apr 25, 2018 2:00 pm
Using JavaScript to automate tasks
Hello,
I want to:
1. Count text fields with specific color using JS (text fields are created manually with PDF-XChange).
2. Insert into them their respective number or string (like SOMETHINGX, SOMETHINGX+1 and so on).
a) clean all fields before step 2
3. Change color of each text box (without mundane, manual work) of each box.
Are these magic tricks possible?
Cheers
I want to:
1. Count text fields with specific color using JS (text fields are created manually with PDF-XChange).
2. Insert into them their respective number or string (like SOMETHINGX, SOMETHINGX+1 and so on).
a) clean all fields before step 2
3. Change color of each text box (without mundane, manual work) of each box.
Are these magic tricks possible?
Cheers
Last edited by JohnSmithUSA on Thu Jul 12, 2018 9:00 am, edited 2 times in total.
- Will - Tracker Supp
- Site Admin
- Posts: 6815
- Joined: Mon Oct 15, 2012 9:21 pm
- Location: London, UK
- Contact:
Re: Using JavaScript to automate tasks
Hi John,
Thanks for the post - This should be possible using JavaScript. We support most of the features of the Adobe JS API. Please see the reference manual here:
https://www.adobe.com/content/dam/acom/ ... erence.pdf
We don't typically write scripts for our users, the onus is on users to write any scripts they need themselves. On rare occasions (i.e. when it's exceedingly quick simple, or when it's of a benefit to a large amount of users) we may write them.
Thanks,
Thanks for the post - This should be possible using JavaScript. We support most of the features of the Adobe JS API. Please see the reference manual here:
https://www.adobe.com/content/dam/acom/ ... erence.pdf
We don't typically write scripts for our users, the onus is on users to write any scripts they need themselves. On rare occasions (i.e. when it's exceedingly quick simple, or when it's of a benefit to a large amount of users) we may write them.
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.
Best regards
Will Travaglini
Tracker Support (Europe)
Tracker Software Products Ltd.
http://www.tracker-software.com
Thank you.
Best regards
Will Travaglini
Tracker Support (Europe)
Tracker Software Products Ltd.
http://www.tracker-software.com
-
- User
- Posts: 6
- Joined: Wed Apr 25, 2018 2:00 pm
Re: Using JavaScript to automate tasks
Ok, I understand. I don't have IT background, but will try to fight on my own.
If anybody has too much free time, I'd be really glad to receive any help. Thanks in advance.
If anybody has too much free time, I'd be really glad to receive any help. Thanks in advance.
- Will - Tracker Supp
- Site Admin
- Posts: 6815
- Joined: Mon Oct 15, 2012 9:21 pm
- Location: London, UK
- Contact:
Re: Using JavaScript to automate tasks
Hi John,
If you do struggle, we'd be happy to help guide you. Alternately, if you can get the general outline of the script but just can't seem to get it working properly, feel free to sent the document & script and we can help from there.
Cheers,
If you do struggle, we'd be happy to help guide you. Alternately, if you can get the general outline of the script but just can't seem to get it working properly, feel free to sent the document & script and we can help from there.
Cheers,
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.
Best regards
Will Travaglini
Tracker Support (Europe)
Tracker Software Products Ltd.
http://www.tracker-software.com
Thank you.
Best regards
Will Travaglini
Tracker Support (Europe)
Tracker Software Products Ltd.
http://www.tracker-software.com
-
- User
- Posts: 6
- Joined: Wed Apr 25, 2018 2:00 pm
Re: Using JavaScript to automate tasks
Adobe API js handbook, page 447
var count = 0;
for ( var i=0; i<this.numFields; i++) {
var fname = this.getNthFieldName(i);
if ( this.getField(fname).type == "text" ) count++; }
console.println("There are " + count + " text fields.");
Result:
There are 0 text fields.
undefined
This script doesn't work... or it has different understanding of text field. I want to calculate text field created by user.
var count = 0;
for ( var i=0; i<this.numFields; i++) {
var fname = this.getNthFieldName(i);
if ( this.getField(fname).type == "text" ) count++; }
console.println("There are " + count + " text fields.");
Result:
There are 0 text fields.
undefined
This script doesn't work... or it has different understanding of text field. I want to calculate text field created by user.
- Tracker Supp-Stefan
- Site Admin
- Posts: 17941
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
- Contact:
Re: Using JavaScript to automate tasks
Hello John,
Those should be actual form text fields - and the script will then work and give you their count: Maybe the objects you have are text box annotations?
Can you share with us a sample file with the objects that you want to modify visible - and we will then be able to advise further!?
Regards,
Stefan
Those should be actual form text fields - and the script will then work and give you their count: Maybe the objects you have are text box annotations?
Can you share with us a sample file with the objects that you want to modify visible - and we will then be able to advise further!?
Regards,
Stefan
-
- User
- Posts: 1
- Joined: Thu Jul 12, 2018 6:26 pm
- TrackerSupp-Daniel
- Site Admin
- Posts: 8601
- Joined: Wed Jan 03, 2018 6:52 pm
Re: Using JavaScript to automate tasks
Hello Peydisegna,
I see that as Stefan mentioned before, you've used text comments, instead of form fields.
For this to work you will need to use Form fields, This article should help you:
https://www.pdf-xchange.com/knowle ... -PDF-forms
I see that as Stefan mentioned before, you've used text comments, instead of form fields.
For this to work you will need to use Form fields, This article should help you:
https://www.pdf-xchange.com/knowle ... -PDF-forms
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
-
- User
- Posts: 6
- Joined: Wed Apr 25, 2018 2:00 pm
Re: Using JavaScript to automate tasks
Why my script doesn't work?
var count = 0;
for ( var i=0; i<this.numComments; i++) {
var fname = this.getNthCommentName(i);
if ( this.getField(fname).type == "comment" ) count++; }
console.println("There are " + count + " comments.");
var count = 0;
for ( var i=0; i<this.numComments; i++) {
var fname = this.getNthCommentName(i);
if ( this.getField(fname).type == "comment" ) count++; }
console.println("There are " + count + " comments.");
- Tracker Supp-Stefan
- Site Admin
- Posts: 17941
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
- Contact:
Re: Using JavaScript to automate tasks
Hello John,
Where are you getting those scripts from?
I could not find methods with those names you try to use here:
https://www.adobe.com/content/dam/acom/ ... erence.pdf
So if you got this code from somewhere else - most likely those were defined elsewhere and you missed their definition?
Please try something like this to work with annotations on a PDf's page.
Cheers,
Stefan
Where are you getting those scripts from?
I could not find methods with those names you try to use here:
https://www.adobe.com/content/dam/acom/ ... erence.pdf
So if you got this code from somewhere else - most likely those were defined elsewhere and you missed their definition?
Please try something like this to work with annotations on a PDf's page.
Code: Select all
var annots = this.getAnnots({
nPage:0,
nSortBy: ANSB_Author,
bReverse: true
});
console.show();
console.println("Number of Annotations: " + annots.length);
var msg = "%s in a %s annot said: \"%s\"";
for (var i = 0; i < annots.length; i++)
console.println(util.printf(msg, annots[i].author, annots[i].type,
annots[i].contents));
Stefan