Automation: Specific color for specific words in multiple PDFs

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

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

Post Reply
pdf-anna
User
Posts: 13
Joined: Mon May 24, 2021 8:59 am

Automation: Specific color for specific words in multiple PDFs

Post by pdf-anna »

Hi,

i have to read a lot of academic journals.

Is it possible to automate a function so that I have to click just on one button instead of doing it every time manually: Define different colors for different words and highlight them with 1 click.

Example:
red: test, alpha
blue: monitor, result
green: statistic

I know that I can open muliple PDFs and do the coloring for each word but all open PDFs.

However, in the longrun, I would like to have an automated function where I just click on 1 button and thats it.

Do you know a solution for that?
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17810
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Automation: Specific color for specific words in multiple PDFs

Post by Tracker Supp-Stefan »

Hello pdf-anna,

Welcome to our forums.

The code below can be executed through the console (Ctrl + J to start it):

Code: Select all

var d = app.activeDocs;
for (var j = 0; j < d.length; j++){
  for (var p = 0; p < d[j].numPages; p++){
    var numWords = d[j].getPageNumWords(p);
    for (var i = 0; i < numWords; i++){
      var ckWord = d[j].getPageNthWord(p, i, true);
      if ( ckWord == "SearchWord"){
        var q = d[j].getPageNthWordQuads(p, i);
	 var l = d[j].addAnnot({
	   page: p,
	   type: "Highlight",
	   author: "PDF-XChange Editor",
	   strokeColor: color.green,
          quads: q,
	 });
      }
    }
  }
}
And it will highlight all the instances of your "SearchWord" in any of your opened documents in green.

Some of the operations in the above script are executed in "privileged context" - so I do not think you can currently make this as a toolbar button, and will have to do it through the console.

Kind regards,
Stefan
pdf-anna
User
Posts: 13
Joined: Mon May 24, 2021 8:59 am

Re: Automation: Specific color for specific words in multiple PDFs

Post by pdf-anna »

First of all, thank you for your fast reply.

Thank you for welcoming me :-).

I have some questions:

1) How can I learn or use a pre-defined kit to "code" it by myself? So I can improve myself without asking you all the time.

2) Can I enhance the above code by multiple words and multiple colors as in my example above? Because if I do have to open console for each word and each color, I could too it the way I am used to (top right on Search, then searching the word, then on Settings, highlight all and select the color).

So If I can use multiple words and colors in the console, how would it look like according to my example above?
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17810
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Automation: Specific color for specific words in multiple PDFs

Post by Tracker Supp-Stefan »

Hello pdf-anna,

The above code is written in JS, and there is a specific manual for PDF Files (created by Adobe, but we should support most of it as well):
http://wwwimages.adobe.com/content/dam/ ... erence.pdf

You can indeed run this script for multiple words and multiple colours, sure!
Please note that there are some predefined colours for PDF files, and custom colours can also be specified (take a look at page 193 of the above linked file).

Kind regards,
Stefan
pdf-anna
User
Posts: 13
Joined: Mon May 24, 2021 8:59 am

Re: Automation: Specific color for specific words in multiple PDFs

Post by pdf-anna »

Thank you again for the fast reply.

I will start experimenting :-)

I Still hope that it will be easy as with enhancing the code with "or", like:
... if (ckWord == "SearchWord" or "test" or "alpha") ...
.... strokeColor: color.green ...
... if (ckWord == "beta" or "gamma")
.... strokeColor: color.red...

Something like that.

However, in the long run, I would like to enhance this system via Excel (words, color, type (highlight or underline)). I will highlight / underline always the same words with the same colors. A system I can count on :-)
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17810
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Automation: Specific color for specific words in multiple PDFs

Post by Tracker Supp-Stefan »

Hello pdf-anna,

Here's some help with checking for one of a number of strings:
https://www.tjvantoll.com/2013/03/14/be ... le-values/

Kind regards,
Stefan
User avatar
David.P
User
Posts: 1510
Joined: Thu Feb 28, 2008 8:16 pm

Re: Automation: Specific color for specific words in multiple PDFs

Post by David.P »

Here's something related I wrote 10 years ago 8)

https://forum.pdf-xchange.com/viewtopic.php?f=35&t=9945&hilit=reading#p45277

Image
Revolutionary Killer Feature for Power Reading
David.P
PDF-XChange Pro
pdf-anna
User
Posts: 13
Joined: Mon May 24, 2021 8:59 am

Re: Automation: Specific color for specific words in multiple PDFs

Post by pdf-anna »

@David P.,

this is exactly what I am looking for.

However, not browser based, but it should do it directly in my PDF and save this color coding.

Your homepage does not work anymore :-)
User avatar
David.P
User
Posts: 1510
Joined: Thu Feb 28, 2008 8:16 pm

Re: Automation: Specific color for specific words in multiple PDFs

Post by David.P »

True Anna, that web hosting went down years ago. I have corrected the link now :)
David.P
PDF-XChange Pro
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17810
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Automation: Specific color for specific words in multiple PDFs

Post by Tracker Supp-Stefan »

Hello David.P,

Thanks for bringing this up again, but I am afraid that for the time being we only have the tools and ways to achieve this discussed earlier!

Kind regards,
Stefan
User avatar
David.P
User
Posts: 1510
Joined: Thu Feb 28, 2008 8:16 pm

Re: Automation: Specific color for specific words in multiple PDFs

Post by David.P »

Hello Stefan,

I understand that this is a rather advanced feature which is not that easy to implement.

However, the approach of how this feature was implemented as a browser plugin ten years ago, as well as possible further enhancements, particularly by including automatic keyword detection, can be looked up in the relevant thread in the Donationcoder forum, for those interested:

https://www.donationcoder.com/forum/index.php?topic=24496.msg222984#:~:text=Therefore%20I%20wish%20there%20was%20a%20software%20(or%20online%20service)%20that%20could%20do%20the%20following%3A

Best regards
David
--
PS: An online automatic "key sentences extractor" can be found here:
https://www.textcompactor.com

...and an automatic keyword extractor here:
https://wordcounter.net
David.P
PDF-XChange Pro
pdf-anna
User
Posts: 13
Joined: Mon May 24, 2021 8:59 am

Re: Automation: Specific color for specific words in multiple PDFs

Post by pdf-anna »

Thank you all so far. But it seems to be that I will need to record a macro by doing the perfect mouse clicks step by step and save the process.
User avatar
Dimitar - Tracker Supp
Site Admin
Posts: 1778
Joined: Mon Jan 15, 2018 9:01 am

Re: Automation: Specific color for specific words in multiple PDFs

Post by Dimitar - Tracker Supp »

Hi all,

Unfortunately, we still do not have anything more to offer, so at this point, recording macro seems the be the best option.


Regards.
pdf-anna
User
Posts: 13
Joined: Mon May 24, 2021 8:59 am

Re: Automation: Specific color for specific words in multiple PDFs

Post by pdf-anna »

I know, I am checking it all the time :-(
User avatar
David.P
User
Posts: 1510
Joined: Thu Feb 28, 2008 8:16 pm

Re: Automation: Specific color for specific words in multiple PDFs

Post by David.P »

I would of course be most pleased with such a feature as well -- although admittedly, this feature currently is beyond advanced for any PDF software in existence.

I admit that I paid quite a bit of money for an Acr0bat plugin that makes this feature (partially) possible:

Image

Now that I look it up again, I believe that this tool might even meet Anna's specific requirements, as can be seen here:

https://www.evermap.com/HighlightText.asp#:~:text=Search documents using custom text patterns,in the document without the need to specifically list all possible numbers.

@Tracker Team, I hope it is ok if I mention and link to a third-party product here. Since this feature is not available in PDF-XChange Editor (nor in any other PDF editor for that matter), I believe that the link should be ok for the time being.

One day we might even see a similar feature in PDF-XChange Editor!

Best regards
David
David.P
PDF-XChange Pro
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17810
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Automation: Specific color for specific words in multiple PDFs

Post by Tracker Supp-Stefan »

Hello David.P,

Having the link is fine.
We know you are doing it to help Anna and others and not just to promote the product!

Kind regards,
Stefan
pdf-anna
User
Posts: 13
Joined: Mon May 24, 2021 8:59 am

Re: Automation: Specific color for specific words in multiple PDFs

Post by pdf-anna »

first of all, sorry for my late reply.

thank you for the idea david. i appreciate that.

to inform you all: i downloaded a free macro mouse recorder and replicated each step i have to do always manually. so now i click on play and just wait a few seconds.

dear support team, is there a shortcut for "highlight all"? so far is after "search", on the right sight preferences, the 4. from below - mark search results and then the 1. option "highlight".

these are a lot of mouse clicks but i prefer a keyboard shortcut for that.
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17810
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Automation: Specific color for specific words in multiple PDFs

Post by Tracker Supp-Stefan »

Hello pdf-anna,

Glad to hear you've found a solution that works for you with those macros!
You can create custom shortcuts for most of the commands in the Editor:
https://www.pdf-xchange.com/knowle ... the-Editor

And you likely need this command:
image.png
Kind regards,
Stefan
pdf-anna
User
Posts: 13
Joined: Mon May 24, 2021 8:59 am

Re: Automation: Specific color for specific words in multiple PDFs

Post by pdf-anna »

dear stefan,

i want to thank you so much for the hint.

this custom shortcut function is such a productivity boost. it makes macro recordings faster and less error-prone.
User avatar
Paul - Tracker Supp
Site Admin
Posts: 6829
Joined: Wed Mar 25, 2009 10:37 pm
Location: Chemainus, Canada
Contact:

Automation: Specific color for specific words in multiple PDFs

Post by Paul - Tracker Supp »

:)
Best regards

Paul O'Rorke
Tracker Support North America
http://www.tracker-software.com
Post Reply