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

Help with simple repagination script

Engaged ,
Jan 13, 2024 Jan 13, 2024

I have a 100 page cookbook that I need to print 2 up side by side on an 8.5x11 in page. Since this is not a booklet, using the Print As Booklet option won't work.

 

I created the output in InDesign and printed the pagesto a PDF.

I would like to now reorder the pages using this method:

4,1  2,3  8,5 6,7  etc.

This will allow me to print 2 up double sided and original page 1 will be married up with original page 2 and so on for the entire document.

A javascript loop might look something like:

let pages=document.pages;

let pagecount=pages.length;

for (var p=3;p<pagecount;p+=4) {

let fourthPage=pages.splice(p,1);

pages.splice(p-3,0,fourthPage);

}

Basicallly it would extract every fourth page and insert it at the front of those 4 pages resulting in a new page order.

 

Please tell me someone can help with this. It seems like such a simple request. Any help would be appreciated. 

 

TOPICS
How to , JavaScript , PDF
961
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 ,
Jan 13, 2024 Jan 13, 2024

@try67 , @Nesa Nurani , @Thom Parker 

ABAMBO | Hard- and Software Engineer | Photographer
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 ,
Jan 14, 2024 Jan 14, 2024

This code should do the trick:

 

for (var p=3; p<this.numPages; p+=4) {
	this.movePage(p, p-4);
}
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
Engaged ,
Jan 14, 2024 Jan 14, 2024

Thanks a ton. This is great but what on Earth is going on with the javascript portion of Acrobat?

I select Use JavaScript and a panel opens with 4 options:

Debugger

Document Javascript Strings

All Javascript Strings

Document Actions

 

I figured since I only want to run this script one time, I'd run it from the console in the Debugger. NOPE.

I figured that I would add it to the Document Strings and was able to Add It, but not execute it

I went back to Debugger to see if it would show up under available scripts...no luck, still can't execute it.

So I look at All Javascript Strings and I can see my previous function was added, still no way to execute it.

So I try Document Actions and it is a set of triggers-none of which work for me because presumably, I will print this a few hundred times and only want this run right now. 

 

What am I missing? How do I run my function defined in Document Strings this one time? Thanks for your help.

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
Engaged ,
Jan 14, 2024 Jan 14, 2024

I got it to work by invoking the function call after the definition. Is there a way to ensure that it only happens once. There doesn't seem to be any indication about when it will happen after I define the document string. So I quickly deleted the script after it ran successfully. Thanks for any suggestions.

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 ,
Jan 14, 2024 Jan 14, 2024

You need to run it from the JS Console. What happens when you try to do so?

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 ,
Jan 14, 2024 Jan 14, 2024

Another option is to run it from a Custom Command or an Action.

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
Engaged ,
Jan 14, 2024 Jan 14, 2024

When I open the debugger for console access, it asks if I want enable the debugger and I click YES. Then I view Scripts and Console (which shows two boxes presumably one for each though they aren't labeled).

It appears that the script box wants predefined scripts because of the UI having a selection rectangle in it. No scripts present. neither button below the first panel does anything.

The second box appears to be the console. I can type in that box by clicking the pencil icon. But nothing happens when I press enter. I can even define a function and call it, but it's just text--nothing active.

The only other options are buttons with no labels at the top of the Debugger window.

One is an arrow--pressing it does nothing.

The next is a green circle--pressing it does nothing as well.

The next is a red X -- you guessed it- does nothing when pressed. 

Next, there are three buttons that appear to be related to breakpoints -- nothing.

The callstack selection control shows nothing.

In the Inspect portion of the Debugger, you can select various options like BreakPoints, Call Stack, Global and Local Variables. None of which do anything at all. Below it is a window that must be the "watched" content from the Inspect context. It says Variable and looks selectable. Does nothing.

The pencil, new page and trash buttons do nothing.

 

This is true whether I add fiunctions to the document strings or not.

JS Debugger in Acrobat.-02.jpgexpand image

This is the JS debugger open in Acrobat. I have entered several lines with function declarations and function calls but cannot get them to work or give errors at all. 

 

I was able to reorder my pages which was the ultimate goal, but now I have realized that Acrobat won't print 2UP without adding arbitrary and unavoidable margins to your document. So now, I am going to try to script the creation of a new document that is letter size and automate copying pages from my existing PDF to the new PDF in a manner that puts them 2UP left to right. If But the thought of doing that without a working debugger or at least a functioning console seems pretty bleak.

 

Still, I reallly appreciate your help and taking the time to look into this. I hope I am doing something wrong.

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
Engaged ,
Jan 14, 2024 Jan 14, 2024

Just another quick update. So I added the function declaration to the JS Document Strings and then called the function in the same window. When I closed the window, the function call happened and my pages were reordered perfectly. Thanks to you. However, I never saved the document.

 

When I selected Create Custom Tool or Command, I got an error message saying I had to disable New Acrobat. So I select Disable New Acrobat from the menu and I'm told that I have to restart the app. Click  restart and it asks if I want to save my document. I click NO, do not save document because I wanted to do it differently. It closes my documents and quits out of Acrobat. END OF STORY

 

So I relaunch Acrobat and load my document expecting to see the original page order, but nope. It's the altered page order that I said NOT to save. Not only that, but I'm still in New Acrobat mode.

 

Am I doing something wrong here? It really feels like Acrobat just refuses to do the most basic things like closing a document without saving changes or changing to regular old Acrobat DC from New Acrobat. 

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 ,
Jan 15, 2024 Jan 15, 2024
LATEST

It's a bit difficult to follow your entire narrative. I suggest you focus on one thing and try to get it working from there, like using the Console. Do NOT embed the code in the file. If you do that it means it will run each time you open the file, so it appears as the file has been saved with the changes, even though it wasn't.

All you need to do is paste the code I provided into the text area in the lower part of the Console window, select all of it with the mouse/keyboard and press Ctrl+Enter and it will run. Then save the file and you're done.

Regarding the new Acrobat UI: Yes, it's terrible. You should be able to disable it via the Options menu at the top-left corner of the application.

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