Skip to main content
Known Participant
December 8, 2022
Question

Acrobat TrimBox math results in unexpected value

  • December 8, 2022
  • 2 replies
  • 1064 views

Using JavaScript in Acrobat to modify MediaBox size,
the result is not the expected value (

for (var i=0; i<this.numPages; i++) {
    var ar = this.getPageBox("Media", i);
	console.println("Before: page " + (i+1))
	console.println("MediaBox = " + this.getPageBox("Media"));
// increase dimension of MediaBox by 36 points by moving from 0,0 to -36,-36, and then increasing box width and height.
	ar[0] = ar[0] - 36
	ar[1] = ar[1] + 72
	ar[2] = ar[2] + 72
	ar[3] = ar[3] - 36

    this.setPageBoxes("Media", i, i, ar);

	console.println("After: page " + (i+1))
	console.println("MediaBox = " + this.getPageBox("Media"));
}

The resultant before/after values reveal:

  • Before: page 1
    MediaBox = 0,504,504,0
  • After: page 1
    MediaBox = -35.99998474121094,576,576,-35.99998474121094 true

The zeros should have become -36, but didn't. Why?
Also, any attempt I try to round the values using math.rounding(x) just fails, though I"m still hammering on/learning through.
Ideas on calculation issue?

This topic has been closed for replies.

2 replies

try67
Community Expert
Community Expert
December 8, 2022

That is strange... But you can use Math.round(x) to round them to the nearest integer.

Known Participant
December 9, 2022

I've not been successful yet with this; I don't think I have the construction correct, or Acrobat doesn't recognize it.
I've also just learned about Floating Point Arithmetic precision, where 3-1≠2, so there may be answers there, too.
www.w3schools.com Floating Precision 

try67
Community Expert
Community Expert
December 9, 2022

Post your code.

Bernd Alheit
Community Expert
Community Expert
December 8, 2022

What happens when you round the values?