Add PageBox to Document Info Metadata

Adobe Community Professional ,
Nov 28, 2018

Copy link to clipboard

Copied

I would like to add say the Media Box or Trim Box info to the document info metadata, such as title or subject.

It is apparently very easy to add a static string to the document metadata, such as:

this.info.subject = "My Text String"; // adds text string to the document subject metadata

As a newb to scripting, I am having problems adding a variable based off the required page box rather than a hard coded string of static text.

This topic thread is a good example of what I would like to add to the metadata:

Checking Trim size Quickly

function ThePageSize(){

var aRect = this.getPageBox("Trim");

var width = aRect[2] - aRect[0];

var height = aRect[1] - aRect[3];

app.alert("Trim: " + Math.round(width*0.3528) + " mm x "

+ Math.round(height*0.3528) + " mm");

}

Line 5 where it pulls in the bounding size and converts it to metric with some static text is what I would like to add to the metadata.

I’m sure that I am missing something basic and I have not been able to find any examples to adapt. Can anybody please point me in the right direction?

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Simply replace app.alert(...); with this.info.subject = ... ;

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

796

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

Add PageBox to Document Info Metadata

Adobe Community Professional ,
Nov 28, 2018

Copy link to clipboard

Copied

I would like to add say the Media Box or Trim Box info to the document info metadata, such as title or subject.

It is apparently very easy to add a static string to the document metadata, such as:

this.info.subject = "My Text String"; // adds text string to the document subject metadata

As a newb to scripting, I am having problems adding a variable based off the required page box rather than a hard coded string of static text.

This topic thread is a good example of what I would like to add to the metadata:

Checking Trim size Quickly

function ThePageSize(){

var aRect = this.getPageBox("Trim");

var width = aRect[2] - aRect[0];

var height = aRect[1] - aRect[3];

app.alert("Trim: " + Math.round(width*0.3528) + " mm x "

+ Math.round(height*0.3528) + " mm");

}

Line 5 where it pulls in the bounding size and converts it to metric with some static text is what I would like to add to the metadata.

I’m sure that I am missing something basic and I have not been able to find any examples to adapt. Can anybody please point me in the right direction?

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Simply replace app.alert(...); with this.info.subject = ... ;

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

797

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
Nov 28, 2018 0
Most Valuable Participant ,
Nov 28, 2018

Copy link to clipboard

Copied

Simply replace app.alert(...); with this.info.subject = ... ;

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...
Nov 28, 2018 1
Adobe Community Professional ,
Nov 28, 2018

Copy link to clipboard

Copied

Thank you try67, as I answered this myself while you were replying to my post, after so many false starts it finally became obvious! However I really appreciate your reply, I have marked your answer as correct!

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...
Nov 28, 2018 0
Most Valuable Participant ,
Nov 28, 2018

Copy link to clipboard

Copied

It may be of no importance in this case, but for those reading this in the future, remember that a PDF can have any number of pages, and each page can be different size. This is why it is not document metadata as standard.

Confusingly, Acrobat shows a page size AS IF it is document metadata, in Properties. In fact, it just shows the size of the current page.

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...
Nov 28, 2018 2
Adobe Community Professional ,
Nov 28, 2018

Copy link to clipboard

Copied

Thanks Test Screen Name – I agree, in this use case it is presumed that the input file is either a single page or all pages are the same size.

It took me a while to work out that one had to add this.pageNum to the code for the current page:

Re: Checking Trim size Quickly

The reason that I wanted to add the trim box info to metadata was for use after imposition, as detailed in the following topic thread:

Re: paste "Trimsize" after impostion

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...
Nov 28, 2018 0
Adobe Community Professional ,
Nov 28, 2018

Copy link to clipboard

Copied

Just curious... as this.info.title = "My Text String”; will replace any existing title, is it possible to either add the new text as a prefix or suffix to the existing entry?

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...
Nov 28, 2018 0
Most Valuable Participant ,
Nov 28, 2018

Copy link to clipboard

Copied

Sure, like this:

this.info.title = this.info.title + "My Text String";

Or:

this.info.title = "My Text String" + this.info.title;

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...
Nov 28, 2018 2
Adobe Community Professional ,
Nov 28, 2018

Copy link to clipboard

Copied

Thank you try67, I am not sure how long it would have taken me to figure that one out!

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...
Nov 28, 2018 0
Adobe Community Professional ,
Nov 28, 2018

Copy link to clipboard

Copied

OK, I think I have it now!

var aRect = this.getPageBox("Media");

var width = aRect[2] - aRect[0];

var height = aRect[1] - aRect[3];

this.info.subject = ("Media: " + Math.round(width*0.3528) + " mm x "

+ Math.round(height*0.3528) + " mm");

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...
Nov 28, 2018 0