Skip to main content
Inspiring
June 18, 2020
Answered

Execute Javascript in Adobe acrobat pro, to select all page content and center it.

  • June 18, 2020
  • 2 replies
  • 3150 views

I have a two page document &, I want to use Action Wizard to center the page contents, using an Exectute Javascript command. Unfortunatelly I know nothing about Javascript, can anyone please help me with a script do do this?

 

All the information on the attached two page pdf is currently aligned to the top left, I cannot adjust how its printed to PDF because it is outputted via an ancient 16bit program.

 

Thanks, in advance for any help and advice!

John

This topic has been closed for replies.
Correct answer John .

Duplicate the setPageBoxes command, replacing "Crop" with the these strings:

Art
Bleed
Media
Trim


Thanks for your help again try67

2 replies

try67
Community Expert
June 18, 2020

While JS can't select or move (static) page contents, it can add white-space to a page by setting the page boxes to a different size (ie, cropping it). Try this code to add an half-inch white space to the left side of all the pages in the file (and take it off the right side):

 

 

for (var p=0; p<this.numPages; p++) {
	var pageBox = this.getPageBox("Crop", p);
	var pageWidth = pageBox[2]-pageBox[0];
	var pageHeight = pageBox[1]-pageBox[3];
	this.setPageBoxes("Crop", p, p, [-36, pageHeight, pageWidth-36, 0])
}

 

John .Author
Inspiring
June 18, 2020

Thanks for the help, that worked a treat!

John .Author
Inspiring
June 19, 2020

You might have to change the other page boxes, too, such as Trim, Art and Media.


Hi try67 thanks for the quick reply.

I'm new to all this & know nothing about JS. How do I change the other page boxes?

I just tried changing the scripts "Page" to Media, Art & Trim, but that didn't work.

Bernd Alheit
Community Expert
June 18, 2020

Javascript can't select the objects.

John .Author
Inspiring
June 18, 2020

Oh, is there anyway I can achieve my goal, using the Action wizard, or Js?

 

I am having to make this process as simple as possible, for someone else to use.