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

How do you loop an action in Acrobat 11 Pro

Explorer ,
Jul 05, 2018 Jul 05, 2018

Hi,

I have an action which prints a batch of pdf files. It is important that the files are printed in a particular sequence. This all works fine. However I now want to print multiple copies of the entire batch keeping the same sequence per batch.

I have tried editing the .sequ file by copying the entire batch several times. However, the additional batches are just ignored. It seems the action recognises that it has already printed the file and does not repeat it for duplicates (Scenario A).

I have found a workaround solution to this by creating multiple copies of the same folder with the same files. Now when I edit the .sequ file by copying the entire batch several times but referring to the different folders, there is no problem (Scenario B).

Examples:

Scenario A - This will only print one copy of Doc 1, Doc 2 and Doc 3 in sequence:

          <Sources>

                    <File path="/C/Folder/Doc 1.pdf"/>

                    <File path="/C/Folder/Doc 2.pdf"/>

                    <File path="/C/Folder/Doc 3.pdf"/>

                    <File path="/C/Folder/Doc 1.pdf"/>

                    <File path="/C/Folder/Doc 2.pdf"/>

                    <File path="/C/Folder/Doc 3.pdf"/>

                    <File path="/C/Folder/Doc 1.pdf"/>

                    <File path="/C/Folder/Doc 2.pdf"/>

                    <File path="/C/Folder/Doc 3.pdf"/>

                    </Sources>

          <Group label="Untitled">

                    <Command name="Print" pauseBefore="false" promptUser="false"/>

          </Group>

Scenario B - This will print three copies of Doc 1, Doc 2 and Doc 3 in sequence:

          <Sources>

                    <File path="/C/Folder/Doc 1.pdf"/>

                    <File path="/C/Folder/Doc 2.pdf"/>

                    <File path="/C/Folder/Doc 3.pdf"/>

                    <File path="/C/Folder - Copy (1)/Doc 1.pdf"/>

                    <File path="/C/Folder - Copy (1)/Doc 2.pdf"/>

                    <File path="/C/Folder - Copy (1)/Doc 3.pdf"/>

                    <File path="/C/Folder - Copy (2)/Doc 1.pdf"/>

                    <File path="/C/Folder - Copy (2)/Doc 2.pdf"/>

                    <File path="/C/Folder - Copy (2)/Doc 3.pdf"/>

                    </Sources>

          <Group label="Untitled">

                    <Command name="Print" pauseBefore="false" promptUser="false"/>

          </Group>

My question is:

Is there an easier way to do Scenario B? Is it possible to just loop Scenario A the number times required? If so, how?

Any help would be appreciated. Thanks!

TOPICS
Print and prepress
7.4K
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
LEGEND ,
Jul 05, 2018 Jul 05, 2018

You could consider combining the files to print into one, then the order of printing becomes unimportant. Everything MIGHT get simpler.

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
Explorer ,
Jul 05, 2018 Jul 05, 2018

Sorry, I should have added that each document is stapled separately when printed. So I can't just combine the documents into one.

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 ,
Jul 08, 2018 Jul 08, 2018

If the file-paths are fixed and known in advance then this can be done with a script, where you would hard-code the paths of the files and then print them in order, how many times you'd like.

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
Explorer ,
Jul 08, 2018 Jul 08, 2018

Thanks for your reply.

Yes the file-paths are fixed. Can you please give me an idea of how to go about writing a script to do this. I have never written a script in Acrobat. I'm more familiar with writing macros in Word and Excel. If you could give me something to start off with that would be great.

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 ,
Jul 08, 2018 Jul 08, 2018

Here's the basic code for opening a file, printing it a number of times and then closing it:

var doc = app.openDoc("/C/Folder/Doc 1.pdf");

if (doc!=null) {

    var pp = doc.getPrintParams();

    pp.NumCopies = 3;

    doc.print(pp);

    doc.closeDoc(true);

}

You would need to run it from a trusted context, though, such as an Action or directly from the JS-Console.

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
Explorer ,
Jul 08, 2018 Jul 08, 2018

Thanks!

If I understand your script correctly, this will print each document 3 times. This isn't quite what I had in mind. I need to print each file once in a particular order, then repeat the whole batch n number of times. Each document is stapled as it is printed. How can I use your code as a repeating subroutine printing each document once, which is called by another subroutine and passing the document path reference as a parameter?

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 ,
Jul 08, 2018 Jul 08, 2018

The example above prints a single document 3 times. It can be converted to a more generic function, like this:

function printFileMultipleTimes(filePath, numCopies) {

    var doc = app.openDoc(filePath);

    if (doc!=null) {

        var pp = doc.getPrintParams();

        pp.NumCopies = numCopies;

        doc.print(pp);

        doc.closeDoc(true);

    }

}

You can then use it like this, for example:

printFileMultipleTimes("/C/Folder/Doc 1.pdf", 1);

printFileMultipleTimes("/C/Folder/Doc 2.pdf", 1);

printFileMultipleTimes("/C/Folder/Doc 3.pdf", 1);

printFileMultipleTimes("/C/Folder/Doc 1.pdf", 1);

printFileMultipleTimes("/C/Folder/Doc 2.pdf", 1);

printFileMultipleTimes("/C/Folder/Doc 3.pdf", 1);

This will print all three files, one after another, two times (one copy each time).

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
Explorer ,
Jul 08, 2018 Jul 08, 2018

Many Thanks!

This looks good. Let me try it out! In the meantime, is there a way to just loop the calling routines? If not, this is fine!

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 ,
Jul 09, 2018 Jul 09, 2018

Of course. For example:

for (var i=1; i<=3; i++) {

    printFileMultipleTimes("/C/Folder/Doc 1.pdf", 1);

    printFileMultipleTimes("/C/Folder/Doc 2.pdf", 1);

    printFileMultipleTimes("/C/Folder/Doc 3.pdf", 1);

}

That will print the set of three files three times.

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
Explorer ,
Jul 09, 2018 Jul 09, 2018

Perfect. Let me try it out and get back to you if I have a problem.

I really appreciate your help with this. Thank you!

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
Explorer ,
Jul 09, 2018 Jul 09, 2018

I have created the code and pasted into the JavaScript console window. Is this the right place to execute the script?

I have pasted your code and modified the file references.

I have placed the 'function' before the 'for' loop. Is this correct?

Then I selected the line with the 'for' loop and pressed Ctrl+Enter. I got this error message:

SyntaxError: missing } in compound statement

2:Console:Exec

undefined

I can't see anything wrong with the script. Please advise if I am doing anything wrong in these steps.

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 ,
Jul 09, 2018 Jul 09, 2018

You need to select all of the code with the mouse before running it from

the Console window.

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
Explorer ,
Jul 09, 2018 Jul 09, 2018

Almost there.

How can I turn off the print dialog box in the doc.print(pp); command so that it prints without user input?

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 ,
Jul 10, 2018 Jul 10, 2018

Before the print command, add this line:

pp.interactive = pp.constants.interactionLevel.automatic;

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
Explorer ,
Jul 10, 2018 Jul 10, 2018

I want to be able to change which printer I am using. Is this the right command?

pp.printerName = "myprintername";

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 ,
Jul 10, 2018 Jul 10, 2018

Yes. To make sure you're using the correct printer name run this code from the Console to get the list of internal names:

app.printerNames.join("\n");

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
Explorer ,
Jul 10, 2018 Jul 10, 2018

Also, once the script is finalized, can I save it as a file and execute the file, or must I always copy it into the console?

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 ,
Jul 10, 2018 Jul 10, 2018

You can save it to a .js file and install it as a folder-level script, or as an Action file (.sequ).

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
Explorer ,
Jul 10, 2018 Jul 10, 2018

app.printerNames.join("\n"); doesn't work. Gives "undefined" as output.

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 ,
Jul 10, 2018 Jul 10, 2018

Are you sure you're selecting the code before running it?

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
Explorer ,
Jul 10, 2018 Jul 10, 2018

Yes, I have entered only this one line in the console. Then selected the entire line and pressed Ctrl+Enter.

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 ,
Jul 10, 2018 Jul 10, 2018

If there are no printers then it's not going to work... Did it work until

now?

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
Explorer ,
Jul 10, 2018 Jul 10, 2018

Yes I have many printers installed. I can find the system name using an Excel Macro. Presumably this would be the same name to set in the javascript. Is that right?

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 ,
Jul 10, 2018 Jul 10, 2018

I can't say for sure. The printerNames list is the only reliable way of

getting the actual values...

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