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

Moving Whole Pages

New Here ,
Nov 12, 2009 Nov 12, 2009

Hello,

Is it possible to swap an entire page and its contents position with another page withing the same document? 

Any help would be greatly appreciated. 

TOPICS
Scripting
1.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
Guide ,
Nov 13, 2009 Nov 13, 2009

Try this:

function swapPages(p0, p1)
{
if (p0 == p1) return true;

var pages = app.activeDocument.pages;

var pg0 = pages.itemByName(''+p0);
var pg1 = pages.itemByName(''+p1);

if ( pg0.documentOffset > pg1.documentOffset ) return swapPages(p1,p0);

try {
  pg1.move(LocationOptions.BEFORE,pg0);
  pg0.move(LocationOptions.AFTER,pages.itemByName(''+p1));
  return true;
  }
catch(ex) {return false;}
}

// usage:
swapPages(5,8);

@+

Marc

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 ,
Nov 15, 2009 Nov 15, 2009

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 ,
Nov 16, 2009 Nov 16, 2009

Hello Marc,

I wanted to give your function (thank you for that!) a little UI using a prompt to feed in the two page numbers.

First I tried the following:

var a = prompt(
    "",
    "1,"+app.activeDocument.pages.length, //Predefined page numbers: first & last page

    "Insert TWO page numbers for swapping pages sepparated by a comma."+"\n"+"First and last page of the document are:"
    );

swapPages(a);

That doesn't work as expected. I had a test with a 12-pages document and "$.writeln(a);" wrote "1,12" to the console of the ESTK.

Error: "p0 is not defined"

Why isn't it posible to use the string "1,12" to feed the function?

I was looking for a solution, so I enhanced the code by:

var b=a.split(",");

swapPages(b[0],b[1]);

That is working now. But still the question remains…

Uwe

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 ,
Nov 16, 2009 Nov 16, 2009

If you want a UI, you can try this script: http://forums.adobe.com/message/2376190#2376190

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 ,
Nov 16, 2009 Nov 16, 2009

Laubender wrote:


That is working now. But still the question remains…

Uwe

Because you fed the function a single string rather than two arguments.

Harbs

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 ,
Nov 16, 2009 Nov 16, 2009
LATEST

Thank you, Harbs. So now I know that the comma in the function call cannot be replaced by a string.

Uwe

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 ,
Nov 16, 2009 Nov 16, 2009

Oops. Forget the error message. This was a mistake. Error was "Object is invalid".

Uwe

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