Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Rearranging pages in Acrobat by specific keywords in the text

Community Beginner ,
Dec 16, 2019 Dec 16, 2019

Thanks in advance for help anyone can give. I'm trying to figure out how to rearrange pages by keywords already in the text. For example: We have a PDF with 100 invoices for band books and want to arrange them by instrument. Using the search function, I can find every place the word "Flute, or Trumpet" appears, but I'm hoping to find a way to search for "Flute" and then move those pages together to the top of the PDF. Repeating this for each instrumentation until all 100 pages are rearranged in the order we need.

 

The only way I know of to rearrange pages, is by selecting each thumbnail (either in the thumbnail preview bar at the side, or in the "organize pages" function) and manually moving them into place. A few searches I've done lead me to think I need to use some sort of Script? I'm still in the learning phase, and don't understand yet what that means. 

TOPICS
Acrobat SDK and JavaScript
20.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Community Beginner , Dec 16, 2019 Dec 16, 2019

You're Awesome!! That's exactly the action I was picturing being able to do! 

Translate
Community Expert , Apr 27, 2022 Apr 27, 2022

Hi,

Here is a new file with an action wizard and a field with the script.

Previously I told you somethin wrong ("In this script the word is used as a variable"). This is something I though to do but I didn't. So you can look for "2 Black Titans"... and you can (normally) search from 1 up to several numbers of words.

@+

 

Translate
New Here ,
Apr 26, 2022 Apr 26, 2022

This is not sorting out the pages

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 26, 2022 Apr 26, 2022

Before the script:

Capture_d’écran_2022-04-26_à_20_41_14.png

 

The script:

Capture d’écran 2022-04-26 à 20.42.27.png

 

And after the script:

Capture_d’écran_2022-04-26_à_20_42_49.png

 

@+

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 26, 2022 Apr 26, 2022

Mubasher007_0-1650999636512.png

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 26, 2022 Apr 26, 2022

and how you are adding the script in the PDF file? Using JavaScript tool?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 26, 2022 Apr 26, 2022

You can't run this script in document level.

Either you copy/paste the script in the console then select all and press the Enter key (numerical panel) or you install the action wizzard attached in the file I shared.

@+

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 26, 2022 Apr 26, 2022

Through which app that wizard will be installed? It says App associated to open this is not available.

Mubasher007_0-1651037680413.png

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 26, 2022 Apr 26, 2022

Or do I need to paste the file in Installation directory? If yes in which location?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 26, 2022 Apr 26, 2022

OK, I have installed the Action Wizard now it is working. 
Can I add Keywords, 

1. 2 Black Titans

2. 2 Grey Titans

3. 2 Blue Titans

4. 2 White Titans

 

In this same code? If yes, do I need to add space between words? Thanks for your help. After this I am 100% done. Thanks alot

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 27, 2022 Apr 27, 2022
var theWords = ["2 Black Titans","2 Blue Titans","2 Grey Titans","2 White Titans", "Originals","Snap","Extender"];
//
d0 = new Date();
debut = util.printd("dd-mm HH:MM", d0);
for (var i = 0; i <= theWords.length; i++) eval("pages" + i + "=[]");
var nbpages = this.numPages;
var page = 0;
var nbmots = 0;
for (var p = 0; p < nbpages; p++) {
    console.clear();
    console.show();
    console.println("Start of processing:" + debut);
    console.println("Process of the page " + (p + 1));
    console.println(nbmots + " word(s) found.");
    var numWords = this.getPageNumWords(p);
    for (var i = 0; i < numWords; i++) {
        var found = 0;
        var ckWord = this.getPageNthWord(p, i, true);
        for (var j = 0; j < theWords.length; j++) {
            if (ckWord == theWords[j]) {
                eval("pages" + j + ".push(p)");
                found++;
                nbmots += 1;
                break;
            }
        }
        if (found) break;
    }
    if (!found) eval("pages" + theWords.length + ".push(p)");
}
for (var i = 0; i <= theWords.length; i++) {
    for (var j = 0; j < eval("pages" + i + ".length"); j++) {
        this.insertPages({
            nPage: this.numPages - 1,
            cPath: this.path,
            nStart: eval("pages" + i + "[j]")
        });
    }
}
this.deletePages(0, nbpages - 1);
df = new Date();
fin = util.printd("dd-mm HH:MM", df);
console.println("End of processing:" + fin);
delta = (df.valueOf() - d0.valueOf()) / 1000 / 60;
console.println("Time of processing:" + delta + " minutes");
switch (nbmots) {
    case 0:
        app.alert("No word has been found, so no page has been moved", 3);
        break;
    case 1:
        app.alert("Only one word has been found, so you will now find it in page 1.", 3);
        break;
    default:
        app.alert(nbmots + " words have been found, so you will now find them on the " + nbmots + " first pages.", 3);
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 27, 2022 Apr 27, 2022

I used this code, but it is not working

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 27, 2022 Apr 27, 2022

It's not possible with this script which only search one word. If you are searching a suit of words, it must be improve...

In this script the word is used as a variable, so we can merge the words to create a variable, but a variable can't start with a digit!

So, in your case, can we onlysearch for "Black Titans" or "Grey Titans"... That would make the script easier!

@+

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 27, 2022 Apr 27, 2022

How we can do that Black Titans?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 27, 2022 Apr 27, 2022

I have to modify the script.

I'll do that in the day.

@+

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 27, 2022 Apr 27, 2022

Thanks a lot for helping. I will be waiting for modified script.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 27, 2022 Apr 27, 2022

Hi,

Here is a new file with an action wizard and a field with the script.

Previously I told you somethin wrong ("In this script the word is used as a variable"). This is something I though to do but I didn't. So you can look for "2 Black Titans"... and you can (normally) search from 1 up to several numbers of words.

@+

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 28, 2022 Apr 28, 2022

Thank you so much brother This is working now.

 

I am wondering if there is a way we can use " 2 Titans / 2 Blak Titans" as a keyword in this script?
I tried it but there is forward slash that is causing problem. Thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 28, 2022 Apr 28, 2022

Hi,

You can search "2 Titans 2 Black Titans" forgetting the slash, that should work, else it's still an other adaptation but I'll not be able to do it today...

@+

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 28, 2022 Apr 28, 2022

I have tried this way, but it is not reading it. Also have tried under quotations and eliminating with backslash, but not executing this.

Ok, I will wait for tomorrow. Thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 29, 2022 Apr 29, 2022

Hi,

Here is the new file including the action wizard.

Normally, you should now be able to look for any special character. Let me know if I found some ones.

@+

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 29, 2022 Apr 29, 2022

Hi, Thanks for this. But it is showing this error.

Mubasher007_0-1651237851758.png

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 29, 2022 Apr 29, 2022

It shows this error if I sort out only these Keywords that you mentioned in his code

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 29, 2022 Apr 29, 2022

It is working now. Thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 29, 2022 Apr 29, 2022

...and do you know why did you get the error?

@+

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 29, 2022 Apr 29, 2022

Same error again

Mubasher007_0-1651238774593.png

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 29, 2022 Apr 29, 2022

Have a look at your PM, I sent you a message for sharing your file.

@+

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines