Highlighted

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

Community Beginner ,
Jun 18, 2020

Copy link to clipboard

Copied

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

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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

Art
Bleed
Media
Trim

Topics

Acrobat SDK and JavaScript, Edit and convert PDFs, How to

Views

268

Likes

Translate

Translate

Report

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

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

Community Beginner ,
Jun 18, 2020

Copy link to clipboard

Copied

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

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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

Art
Bleed
Media
Trim

Topics

Acrobat SDK and JavaScript, Edit and convert PDFs, How to

Views

269

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Jun 18, 2020

Copy link to clipboard

Copied

Javascript can't select the objects.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Community Beginner ,
Jun 18, 2020

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Most Valuable Participant ,
Jun 18, 2020

Copy link to clipboard

Copied

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])
}

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Community Beginner ,
Jun 18, 2020

Copy link to clipboard

Copied

Thanks for the help, that worked a treat!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Community Beginner ,
Jun 19, 2020

Copy link to clipboard

Copied

I was a little hasty & didn't spot an issue.

The pdf is 8.27 x 11.69in, but when I run the script it is 8.26 x 11.69in, which is fine, but when I save and reopen the pdf it is 7.96 x 11.44in. How do I maintain the correct page size, when I re-open the document ?

I modified try67's script slightly to:-

 

/* Re-position Dathan1 */
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, [-22, pageHeight+18, pageWidth-22, +18])
}

Thanks in advance.

John

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Most Valuable Participant ,
Jun 19, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Community Beginner ,
Jun 19, 2020

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Most Valuable Participant ,
Jun 19, 2020

Copy link to clipboard

Copied

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

Art
Bleed
Media
Trim

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Community Beginner ,
Jun 19, 2020

Copy link to clipboard

Copied

Thanks for your help again try67

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Resources
One Stop Solution for Acrobat
Edit a PDF