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

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

Community Beginner ,
Jun 18, 2020 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

TOPICS
Acrobat SDK and JavaScript

Views

1.7K

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
community guidelines

correct answers 3 Correct answers

Community Expert , Jun 18, 2020 Jun 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, pageW
...

Votes

Translate

Translate
Community Expert , Jun 19, 2020 Jun 19, 2020

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

Art
Bleed
Media
Trim

Votes

Translate

Translate
Community Beginner , Jun 19, 2020 Jun 19, 2020

Thanks for your help again try67

Votes

Translate

Translate
Community Expert ,
Jun 18, 2020 Jun 18, 2020

Copy link to clipboard

Copied

Javascript can't select the objects.

Votes

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
community guidelines
Community Beginner ,
Jun 18, 2020 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.

Votes

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
community guidelines
Community Expert ,
Jun 18, 2020 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])
}

 

Votes

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
community guidelines
Community Beginner ,
Jun 18, 2020 Jun 18, 2020

Copy link to clipboard

Copied

Thanks for the help, that worked a treat!

Votes

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
community guidelines
Community Beginner ,
Jun 19, 2020 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

Votes

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
community guidelines
Community Expert ,
Jun 19, 2020 Jun 19, 2020

Copy link to clipboard

Copied

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

Votes

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
community guidelines
Community Beginner ,
Jun 19, 2020 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.

Votes

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
community guidelines
Community Expert ,
Jun 19, 2020 Jun 19, 2020

Copy link to clipboard

Copied

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

Art
Bleed
Media
Trim

Votes

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
community guidelines
Community Beginner ,
Jun 19, 2020 Jun 19, 2020

Copy link to clipboard

Copied

LATEST

Thanks for your help again try67

Votes

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
community guidelines