These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Getting the Pageboxes of PDF and Rename the PDF with Values in Metric mm

Gebhard
Registered: Jul 18 2011
Posts: 25
Answered

Hello Forum,
I want to get the Trimbox of my PDF Documents and rename them to e.g.
Document210x297mm.pdf
I found a script in the Java Api modified by Mr.Kaiser here in the forum, but the conversion is from points to inches, I need mm.
 
var aRect = this.getPageBox("Trim");
var width = aRect[2] - aRect[0];
var height = aRect[1] - aRect[3];
console.println("Page 1 has a width of " + width + " and a height of " +
height);
 
// now just add the conversion from points to inches
console.println("Page 1 has a width of " + (width * (1/72) )+ " inches and a height of " +
(height * (1/72) ) + " inches");
 
//here the code for renaming e.g.Document210x297mm.pdf
Later I will made a folderscript(I know how this will be done)
  
Thank you very much
Gebhard

My Product Information:
Acrobat Pro 8.2.6, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
1 inch = 25.4 millimeters, so just multiple the value in inches by 25.4 and you'll get the size in mm.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Gebhard
Registered: Jul 18 2011
Posts: 25
Hello try67,

thank you for your response.
Yes I know 1 inch = 25.4 millimeters.
//So is this the right code?
console.println("Page 1 has a width of " + (width * (1/72*2,54) )+ " inches and a height of " +
(height * (1/72*2,54) ) + " inches");
Thank you very much
Geghard

try67
Expert
Registered: Oct 30 2008
Posts: 2398
First of all, you need to use periods as the decimal separator, not comma's.
And also, why are you multiplying by 2.54, not 25.4?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Gebhard
Registered: Jul 18 2011
Posts: 25
Hello try67,
sorry my mistake 25,4 is mm and 2,54 is cm
Yes of course this bloody english and metric values, we have much problems in PrePress in rounding them
So you are right I must use Dot not the comma(I´m German)
//So here is the new code:
console.println("Page 1 has a width of " + (width * (1/72*25.4) )+ " inches and a height of " +
(height * (1/72*25.4) ) + " inches");
I hope this is now OK
Gebhard
Gebhard
Registered: Jul 18 2011
Posts: 25
Hello try67,
i made the following script:
var ProcessDocument1e = app.trustedFunction(function()
{
app.beginPriv();

var aRect = this.getPageBox("Trim");
var width = aRect[2] - aRect[0];
var height = aRect[1] - aRect[3];
console.println("Die Seite hat eine Breite von " + (width * (1/72*25.4) )+ " Millimeter und eine Hoehe von " +
(height * (1/72*25.4) ) + " Millimeter");//Output is now in Metric mm
//now i have the problem to round down the Values
//The width is now 209.90278316073946 Millimeter The height is 297.03889427185055 Millimeter
//result should be width 210.mm height 297.00 mm
app.endPriv();
});
// add the menu item
app.addMenuItem({
cName: "DoppelSeitenZuEinzelSeitenJS", // this is the internal name used for this menu item
cUser: "Bemassung in mm hinzufuegen",// this is the label that is used to display the menu item
cParent: "WeitereTools", // this is the parent menu. The file menu would use "File"
cExec: "ProcessDocument1e()",// this is the JavaScript code to execute when this menu item is selected
cEnable: "event.rc = (event.target != null);", // when should this menu item be active?
nPos: 1
});
The output in the Java Console is now shown correctly, BUT this e.g.209.90278316073946 is not a practical value.
So I need to round the value e.g. Bankers rounding 210.00 mm.
I tried many things but I´, not able to do this rounding.
Can you help me again please
kind regards
Gebhard
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Math.round(x) will return the integer nearest to x.
See: http://w3schools.com/jsref/jsref_round.asp

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Gebhard
Registered: Jul 18 2011
Posts: 25
Ok i found that, but where to insert the code? I tired everything but I don´t get it run
Gebhard
Registered: Jul 18 2011
Posts: 25
Ok i found that, but where to insert the code? I treyed everything but I don´t get it run
Sorry klicked twice
try67
Expert
Registered: Oct 30 2008
Posts: 2398
  1. var width = aRect[2] - aRect[0];
  2. var height = aRect[1] - aRect[3];
  3. var widthInMM = Math.round(width * (1/72*25.4));
  4. var heightInMM = Math.round(height * (1/72*25.4));
  5. console.println("Die Seite hat eine Breite von " + widthInMM + " Millimeter und eine Hoehe von " + heightInMM
  6. + " Millimeter");

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Gebhard
Registered: Jul 18 2011
Posts: 25
Hello try67,
thank you very, very much . Its running perfetly.
Is it possible to ask one more?
Now to get this e.g. 210x297mm to my pdffiles when I save them?
e.g. document210x297mm.pdf or document.pdf210x297mm.pdf
Thank you very much
Gebhard
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Accepted Answer
You need to create a trusted saveAs function, and pass the new file path to it.
Search around on the forums, it was discussed many times.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Gebhard
Registered: Jul 18 2011
Posts: 25
Hello try67,

I found it and it runs for me
Thank you very much
Gebhard